package keeto.com.vn.bms.ui.activity;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import keeto.com.vn.bms.config.BMSCore;
import keeto.com.vn.bms.config.IBMSConfig;
import keeto.com.vn.bms.model.AndroidNotificationsModel;
import keeto.com.vn.bms.model.BMSUserModel;
import keeto.com.vn.bms.model.CommentModel;
import keeto.com.vn.bms.model.DetailSergeryModel;
import keeto.com.vn.bms.model.Hospital;
import keeto.com.vn.bms.model.ListSurgeryModel;
import keeto.com.vn.bms.model.ListUserRelatedModel;
import keeto.com.vn.bms.model.Schedule;
import keeto.com.vn.bms.model.TechniciansModel;
import keeto.com.vn.bms.network.IBMSProtocol;
import keeto.com.vn.bms.ui.adapter.ListCommentAdapter;
import keeto.com.vn.bms.ui.adapter.ListTechnicalAdapter;
import keeto.com.vn.bms.ui.widget.IPopupWindow;
import keeto.com.vn.bms.ui.widget.LogoutDialog;
import keeto.com.vn.bms.utils.BMSListener;
import keeto.com.vn.bms.utils.BMSSharedPreferences;
import keeto.com.vn.bms.utils.DateTimeSystem;
import keeto.com.vn.bms.utils.StringUtilities;
import keeto.com.vn.bms.utils.UtilityListView;
import keeto.com.vn.bms.utils.Utils;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;
import android.widget.Toast;

public class CreateScheduleActivity extends Activity implements OnClickListener,OnCheckedChangeListener {
	private EditText etRoom, etFalculty, etExtrasInfo, etnameTechChange,
			etTechniquesRequirement, etPrice, etTittleRate, etContentRate,
			etNameScheldule;
	private Button spCreator, spDoctor, spTypeSchedule, spTimeHours,
			spTimeMinute, spCurrentcy, spHospital, spDateTime, btAddIconChange, spAddTechChange;
	private TextView tvCreator, tvNameCreator, tvNameSchedule, tvSurgery,
			tvNameDoctor, tvNameDoctor1, tvTypeSchedule, tvTypeSchedule1,
			tvTime, tvTimeDate, tvPlace, tvLevelPriority, tvListTechnical,
			tvComment,tvWriteRate,tvTitleName;
	private Button btAdditionalRequirement, btKeySchelde, btCancelSchelde,
			iconDeleteChange, btSendRate, btSentRequirement,
			btIconExc, btApprove, btCancelSchedule1, btPreparation, btCancelScheldules, btnSendReq;
	private ListView lvListTechnical, lvComment;
	private ImageButton ibTittleBack, ibTitleLogin, ibViewListSchedule,
			ibAddSchedule;
	private CheckBox ckbLow,ckbMedium,ckbHigh;
	private ImageButton titleBelow;
	private TextView tvStatusSchedule, tvSurgeryReady;
	private View vDashComment,vComment;
	private RelativeLayout rl_reason;
	private ProgressBar pg_load;
	private Button btPoseNotParticipate;
	private Button viewCommentAll;

	ListTechnicalAdapter listTechnicalAdapter;
	ListCommentAdapter listCommentAdapter;
	private IPopupWindow popupSortby;
	private Calendar cal;
	Date dateFinish;
	private CreateScheduleListener mListener = new CreateScheduleListener();
	
	public static BMSSharedPreferences preferences;
	private DateTimeSystem dateTime;
	private static Context context;
	private int GroupId; 
	private String pageLimit = "10";
	private String pageNumber = "1";
	private String Status = "";
	
	private static final String ITERM_SERGERY = "itemSergery";
	private static final String SERGERY_ID = "SergeryID";
	private static final String ACTION_ITEM_SERGERY = "actionItemSergery";
	private static final String ACTION_ID_SERGERY = "actionIDSergery";
	private static final String ACTION_DEFAULT = "actionDefault";
	private static final String ACTION_SERGERY_NOTIFICATION = "actionSergeryNotification";
	private static final String ITERM_NOTIFICATION_ID = "actionNotificationID";
	private final static String ACTION_CREATE_SURGERY= " Create_Surgery";
	
	//===========================data=============================
	private String strNameSchedule, strDoctor, strTypeSchedule,
			strTime, strRoom, strFalculty, strHospital, strExtrasInfo,strRequire,
			strPrice, strAddress, strAddInfos, strTypeCost;
	private int level;
	private static ArrayList<BMSUserModel> listUser = new ArrayList<BMSUserModel>();
	private static ArrayList<BMSUserModel> listTechniques = new ArrayList<BMSUserModel>();
	private static ArrayList<Schedule> listSchedule = new ArrayList<Schedule>();
	private static ArrayList<Hospital> listHospital = new ArrayList<Hospital>();
	private static ArrayList<CommentModel> listComment = new ArrayList<CommentModel>();
	private ListSurgeryModel itemSergeryModel;
	private DetailSergeryModel itemDetail;
	private ArrayList<TechniciansModel> itemDetailTechniciansModel = new ArrayList<TechniciansModel>(); 
	private ArrayList<ListUserRelatedModel> itemDetailListUserRelatedModel = new ArrayList<ListUserRelatedModel>(); 
	public static int scheduleStatus;
	public static int test = 0;
	private int selectHopitalID;
	private int type =0;
	
	int User_id = 0;
	int Hospital_id = 0;
	int Case_id = 0;
	int SchedUserRole_id = 0;
	String technicalID ="";
	String sergeryID = "";
	private static int pageNumberDoctor = 1;
	private final  static int PAGE_LIMIT = 10;

	public static void actionLaunch(Context context) {
		Intent intent = new Intent(context, CreateScheduleActivity.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		intent.setAction(ACTION_DEFAULT);
		intent.putExtra("", "");
		context.startActivity(intent);
	}
	
	
	public static void actionLaunchSergery(Context context, ListSurgeryModel itemSurgeryModel) {
		Intent intent = new Intent(context, CreateScheduleActivity.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		intent.putExtra(ITERM_SERGERY, itemSurgeryModel);
		intent.setAction(ACTION_ITEM_SERGERY);
		context.startActivity(intent);
	}
	public static void actionLaunchSergery(Context context, String id) {
		Intent intent = new Intent(context, CreateScheduleActivity.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		intent.putExtra(SERGERY_ID, id);
		intent.setAction(ACTION_ID_SERGERY);
		context.startActivity(intent);
	}
	public static void actionLaunchbyCreateSegery(Context context,ListSurgeryModel itemSurgeryModel) {
		Intent i = new Intent(context, CreateScheduleActivity.class);
		i.setAction(ACTION_CREATE_SURGERY);
		i.putExtra(ITERM_SERGERY, itemSurgeryModel);
		context.startActivity(i);
	}

	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.activity_create_schedule);
		test =0;	
		context = CreateScheduleActivity.this;
		preferences = new BMSSharedPreferences(context);
		if(preferences != null){
			type = preferences.getUserPermission(context);
		}
		initView();
		onNewIntent(getIntent());
		
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if(keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN){
			if (action!= null && action.equals(ACTION_CREATE_SURGERY)){
				this.finish();
			}
		}
		
		return super.onKeyDown(keyCode, event);
	}
	
	
	@Override
	protected void onResume() {
		IntentFilter filter = new IntentFilter();
        filter.addAction(IBMSConfig.KEY_ACTION_DELETE_TECHNICAL);
        registerReceiver(receiver, filter);
        IntentFilter filter1 = new IntentFilter();
        filter1.addAction(IBMSConfig.KEY_ACTION_REMOVE_TECHNICAL);
        registerReceiver(receiver1, filter1);
        IntentFilter filter2 = new IntentFilter();
        filter2.addAction(IBMSConfig.KEY_ACTION_ADMIN_TECHNICAL);
        registerReceiver(receiver2, filter2);
		super.onResume();
	}
	
	@Override
    protected void onPause() {
        unregisterReceiver(receiver);
        unregisterReceiver(receiver1);
        unregisterReceiver(receiver2);
        super.onPause();
    }
	
	String action = null;
	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
		action = intent.getAction();
		Bundle bundle = intent.getExtras();
		if(bundle != null){
			if(action.equals(ACTION_DEFAULT)){  //tao lich mo
				setDataForm();   //ham hay chi lay du lieu ra Ã„â€˜e gianh cho spinner set data thui
				spCreator.setEnabled(false);
				tvStatusSchedule.setText(context.getResources().getString(R.string.create_schedule));
				Log.e("ACTION", "ACTION_DEFAULT");
				//chi co nhung thang Maketting, admin, doctor moi nhay duoc vao day
				switch (preferences.getTypeKeyUser(context)) {
				case 1: //maketting
					CreateScheduleAll();
					break;
				case 2: //technical
					ibAddSchedule.setVisibility(View.INVISIBLE);// technical ko dc vao
					break;
				case 3: //doctor
					CreateScheduleAll();
					spDoctor.setText(preferences.getUserLoginFullName(context));
					spDoctor.setEnabled(false);
					break;
				case 4: //admin
					CreateScheduleAll();
					break;
				case 5: //leader cha bao gio nhay vao day dau
					break;
				default:
					break;
				}
			} else if(action.equals(ACTION_ITEM_SERGERY) || action.equals(ACTION_CREATE_SURGERY)){  //xem lich mo
				hideKeybroad(context);
				setDataForm();   //ham hay chi lay du lieu ra de gianh cho spinner set data thui
				itemSergeryModel = (ListSurgeryModel) bundle.get(ITERM_SERGERY);
				tvStatusSchedule.setText(context.getResources().getString(R.string.schedule));
				if(itemSergeryModel != null){
					scheduleStatus = Integer.parseInt(itemSergeryModel.getSurgerySttId());//lay duoc trang thai cua lich mo
				}
				pg_load.setVisibility(View.VISIBLE);
				BMSCore.getInstance(context).taskGetDetailSergery(itemSergeryModel.getSurgeryId(), preferences.getUserAuthKey(context), mListener);
				pg_load.setVisibility(View.VISIBLE);
				BMSCore.getInstance(context).taskGetComment(preferences.getUserAuthKey(context), itemSergeryModel.getSurgeryId(), pageLimit, pageNumber, mListener);
				if(preferences.getTypeKeyUser(context) == 3){  //doctor
					doctorViewSchedule();
					spAddTechChange.setVisibility(View.GONE);
					btAddIconChange.setVisibility(View.GONE);
				} else if(preferences.getTypeKeyUser(context) == 4){  //admin
					actionAdmin();
				} else if(preferences.getTypeKeyUser(context) == 1){ //maketing
					actionMaketing();
				} else if(preferences.getTypeKeyUser(context) == 2){ //ki thuat vien
					actionTechnical();
				}
				//luon hien thi phan comment khi vao action nay
				lvComment.setVisibility(View.VISIBLE);
				etTittleRate.setVisibility(View.VISIBLE);
				etContentRate.setVisibility(View.VISIBLE);
				tvWriteRate.setVisibility(View.VISIBLE);
				btSendRate.setVisibility(View.VISIBLE);
				if(listComment != null && listComment.size() != 0){
					tvComment.setVisibility(View.VISIBLE);
					vDashComment.setVisibility(View.VISIBLE);
				} else {
					tvComment.setVisibility(View.GONE);
					vDashComment.setVisibility(View.GONE);
				}
			} else if(action.equals(ACTION_ID_SERGERY)){
				hideKeybroad(context);
				setDataForm();
				String id = bundle.getString(SERGERY_ID);
				tvStatusSchedule.setText(context.getResources().getString(R.string.schedule));
				if(!id.equals(null)){
					pg_load.setVisibility(View.VISIBLE);
					BMSCore.getInstance(context).taskGetDetailSergery(id, preferences.getUserAuthKey(context), mListener);
					pg_load.setVisibility(View.VISIBLE);
					BMSCore.getInstance(context).taskGetComment(preferences.getUserAuthKey(context), id, pageLimit, pageNumber, mListener);
					showHideViewHead(false);
					showHideViewBackgroundEditText(false);
					showHideViewBotton(false);
				}
			}
		}
	}
	private void actionTechnical() {
		if (itemSergeryModel != null) {
			switch (scheduleStatus) {
			case 5://hoan thanh
				scheduleCompleteorCancel(context.getResources().getString(R.string.surgery_complete));
				break;
			case 4://huy ca mo
				scheduleCompleteorCancel(context.getResources().getString(R.string.surgery_cancel));
				break;
			case 3://BMS san sang
				scheduleCompleteorCancel(context.getResources().getString(R.string.surgery_ready));
				showWriteReason();
				break;
			case 2://BMS xac nhan va sap xep
				scheduleCompleteorCancel(context.getResources().getString(R.string.preparation_surgery));
				showWriteReason();
				break;
			case 1://dang cho BMS xac nhan thang ki thuat vien khong co trang thai nay vi khi ở trang thai nay chua ai co quyen add ki thuat vien vao
				break;

			default:
				break;
			}
			String Schedule_id = itemSergeryModel.getSurgeryId();
			pg_load.setVisibility(View.VISIBLE);
			BMSCore.getInstance(context).taskGetComment(preferences.getUserAuthKey(context), Schedule_id, pageLimit, pageNumber, mListener);
		}
	}
	
	private void showWriteReason() {
		btSentRequirement.setEnabled(true);
		btSentRequirement.setVisibility(View.VISIBLE);
		btSentRequirement.setText(context.getResources().getString(R.string.proposal_not_participate));
		btSentRequirement.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				//check 24 gio
				DateTimeSystem dateTimeSystem = new DateTimeSystem();
				Log.e("TAGGGGGGGGGGGGGGGGG", itemDetail.getCreated_date()+".");
				Log.e("TAGGGGGGGGGGGGGGGGG", "time create lich mo "+StringUtilities.addOneDate(itemDetail.getCreated_date()));//ngay thang nam time tao lich mo
				//14-8-2014 5:4:56
				Log.e("TAGGGGGGGGGGGGGGGGG", "time he thong "+DateTimeSystem.getDateMonthYear1());
				int result = StringUtilities.compareDate1(DateTimeSystem.getDateMonthYear1(), StringUtilities.addOneDate(itemDetail.getCreated_date()));
				Log.e("TAGGGGGGGGGGGGGGGGG", "so sanh "+result);
				if(result == 1){
					Toast.makeText(context, context.getResources().getString(R.string.over_time), Toast.LENGTH_LONG).show();
				} else if(result == 2){
					final Dialog dialog = new Dialog(context);
					dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
					dialog.setContentView(R.layout.custom_dialog);
					dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
					final EditText reason_repair = (EditText) dialog.findViewById(R.id.reason);
					Button send = (Button) dialog.findViewById(R.id.send);
					Button cancel = (Button) dialog.findViewById(R.id.cancel);
					send.setOnClickListener(new OnClickListener() {
						@Override
						public void onClick(View v) {//ky thuat vien gui ly do ko tham gia ca mo
							String reason = reason_repair.getText().toString();
							String ID = preferences.getUserID(context);
							String IDLink = "";
							for (int i = 0; i < itemDetailTechniciansModel.size(); i++) {
								if(ID.equals(itemDetailTechniciansModel.get(i).getUser_id())){
									IDLink = itemDetailTechniciansModel.get(i).getID();
									break;
								}
							}
							String status_id = "2";
							pg_load.setVisibility(View.VISIBLE);
							BMSCore.getInstance(context).taskPoseNotParticipate(status_id, IDLink,reason, preferences.getUserAuthKey(context), mListener);
							dialog.dismiss();
						}
					});
					cancel.setOnClickListener(new OnClickListener() {
						@Override
						public void onClick(View v) {
							dialog.dismiss(); 
						}
					});
					dialog.show();
				}
										
			}
		});
	}
	
	private void actionMaketing() {
		if (itemSergeryModel != null) {
			switch (scheduleStatus) {
			case 5://hoan thanh
				scheduleCompleteorCancel(context.getResources().getString(R.string.surgery_complete));
				break;
			case 4://huy ca mo
				scheduleCompleteorCancel(context.getResources().getString(R.string.surgery_cancel));
				break;
			case 3://BMS san sang
				scheduleCompleteorCancel(context.getResources().getString(R.string.surgery_ready));
				break;
			case 2://BMS xac nhan va sap xep
				scheduleCompleteorCancel(context.getResources().getString(R.string.preparation_surgery));
				break;
			case 1://dang cho BMS xac nhan
				scheduleCompleteorCancel(context.getResources().getString(R.string.waiting_confirm));
				break;

			default:
				break;
			}
			String Schedule_id = itemSergeryModel.getSurgeryId();
			pg_load.setVisibility(View.VISIBLE);
			BMSCore.getInstance(context).taskGetComment(preferences.getUserAuthKey(context), Schedule_id, pageLimit, pageNumber, mListener);
		}
	}
	
	private void actionAdmin() {//trang thai lich mo
		if(itemSergeryModel != null){
			switch (scheduleStatus) {
			case 5: //hoan thanh
				scheduleCompleteorCancel(context.getResources().getString(R.string.surgery_complete));
				break;
			case 4: //huy ca mo
				scheduleCompleteorCancel(context.getResources().getString(R.string.surgery_cancel));
				break;
			case 3: //BMS san sang
				if(preferences.getTypeKeyUser(context) == 2 || preferences.getTypeKeyUser(context) == 1){ //neu la ki thuat vien hoac maketing
					scheduleReady(); 
					spAddTechChange.setVisibility(View.GONE);
					btAddIconChange.setVisibility(View.GONE);
					btAdditionalRequirement.setVisibility(View.GONE);
					btKeySchelde.setVisibility(View.GONE);
					btCancelSchelde.setVisibility(View.GONE);
					btApprove.setVisibility(View.GONE);
					btCancelSchedule1.setVisibility(View.GONE);
				} else {
					scheduleReady();
				}
				break;
			case 2:  //BMS xac nhan va sap xep
				if(preferences.getTypeKeyUser(context) == 2 || preferences.getTypeKeyUser(context) == 1){ //neu la ki thuat vien hoac maketing
					confirmAndSort(); 
					spAddTechChange.setVisibility(View.GONE);
					btAddIconChange.setVisibility(View.GONE);
					btPreparation.setVisibility(View.GONE);
					btCancelScheldules.setVisibility(View.GONE);
					ibAddSchedule.setVisibility(View.INVISIBLE);
				} else {
					confirmAndSort();
					btPreparation.setVisibility(View.VISIBLE);//!!!
					btCancelScheldules.setVisibility(View.VISIBLE);
				}
				break;
			case 1: //dang cho BMS xac nhan
					waitingConfirm();
				break;

			default:
				break;
			}
		}
	}
	
	private void getDataSpinner1(final String[] values, final Button button, final int check) {
		popupSortby = new IPopupWindow(this, R.layout.popup_sortby_layout, null, false, button.getMeasuredWidth(), LayoutParams.WRAP_CONTENT);
		ListView listPopup = (ListView) popupSortby.getView().findViewById(R.id.listPopup);
		if(values != null && values.length != 0){
			ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, R.layout.spinner_adapter, values);
			listPopup.setAdapter(adapter);
		}
		listPopup.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				switch (check) {
				case 1: //User_id
					User_id = getUserID(position);
					break;
				case 2:
					Hospital_id = Integer.parseInt(getHopitalID(position));
					break;
				case 3:
					Case_id = getCaseID(position);
					break;
				case 4:
					technicalID = getTechnicalID(position);
					break;

				default:
					break;
				}
				button.setText(values[position].toString());
				popupSortby.dismiss();
			}
		});
		popupSortby.setAutoHideOutside();
		popupSortby.showAsDropDown(button);
	}
	
	/*
	 * truong hop user laÂ  Bac si.. click xem lich mo o List cac lich mo
	 */
	private void doctorViewSchedule(){  // thang bac i tu list danh sach di vao
		switch (scheduleStatus) {
		case 1://dang cho BMS xac nhan
			scheduleCompleteorCancel(context.getResources().getString(R.string.waiting_confirm));
			btSentRequirement.setVisibility(View.VISIBLE);
			btSentRequirement.setEnabled(true);
			btSentRequirement.setBackgroundResource(R.drawable.moinhat0);
			btSentRequirement.setText(context.getResources().getString(R.string.cancel_request));
			btSentRequirement.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					final Dialog dialog = new Dialog(context);
					dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
					dialog.setContentView(R.layout.dialog_delete);
					dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
					Button ok = (Button) dialog.findViewById(R.id.btn_ok);
					Button cancel = (Button) dialog.findViewById(R.id.btn_cancel);
					ok.setOnClickListener(new OnClickListener() {
						@Override
						public void onClick(View v) {//ky thuat vien gui ly do ko tham gia ca mo
							String Status = "4";
							pg_load.setVisibility(View.VISIBLE);
							BMSCore.getInstance(context).taskSentStatusSchedule(itemSergeryModel.getSurgeryId(), Status, preferences.getUserAuthKey(context), mListener);
							dialog.dismiss();
						}
					});
					cancel.setOnClickListener(new OnClickListener() {
						@Override
						public void onClick(View v) {
							dialog.dismiss(); 
						}
					});
					dialog.show();
				}
			});
			break;
		case 2://xac nhan va sap xep
			scheduleCompleteorCancel(context.getResources().getString(R.string.preparation_surgery));
			test = 0;
			showHideViewHead(false);
			showHideViewBackgroundEditText(false);
			btSentRequirement.setVisibility(View.VISIBLE);
			btSentRequirement.setBackgroundResource(R.drawable.moinhat0);
			btSentRequirement.setText(context.getResources().getString(R.string.cancel_request));
			btSentRequirement.setEnabled(true);
			btSentRequirement.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					final Dialog dialog = new Dialog(context);
					dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
					dialog.setContentView(R.layout.dialog_delete);
					dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
					Button ok = (Button) dialog.findViewById(R.id.btn_ok);
					Button cancel = (Button) dialog.findViewById(R.id.btn_cancel);
					ok.setOnClickListener(new OnClickListener() {
						@Override
						public void onClick(View v) {//ky thuat vien gui ly do ko tham gia ca mo
							String Status = "4";
							pg_load.setVisibility(View.VISIBLE);
							BMSCore.getInstance(context).taskSentStatusSchedule(itemSergeryModel.getSurgeryId(), Status, preferences.getUserAuthKey(context), mListener);
							dialog.dismiss();
						}
					});
					cancel.setOnClickListener(new OnClickListener() {
						@Override
						public void onClick(View v) {
							dialog.dismiss(); 
						}
					});
					dialog.show();
				}
			});
			btApprove.setVisibility(View.GONE);
			btCancelSchedule1.setVisibility(View.GONE);
			etnameTechChange.setVisibility(View.GONE);
			iconDeleteChange.setVisibility(View.GONE);
			
			break;
		case 3:	//!!!		//ca mo da san sang
			scheduleReady();
			break;
		case 4://lich mo da hoan thanh
			scheduleCompleteorCancel(context.getResources().getString(R.string.surgery_cancel));  
			break;
		case 5://lich mo da duoc huy
			scheduleCompleteorCancel(context.getResources().getString(R.string.surgery_complete)); 
			break;

		default:
			break;
		}
	}

	private void CreateScheduleAll() { //tao mot lich mo cho cac User
		tvSurgeryReady.setVisibility(View.GONE);
		showHideViewHead(true);
		showHideViewBackgroundEditText(true);
		showHideViewBotton(false);
		spAddTechChange.setVisibility(View.GONE);
		btAddIconChange.setVisibility(View.GONE);
		btPreparation.setVisibility(View.GONE);
		btCancelScheldules.setVisibility(View.GONE);
		btSentRequirement.setVisibility(View.VISIBLE);
		etNameScheldule.setText("");
		spDoctor.setText("");
		if(preferences.getGroupID(this).equals("3")){
			spTypeSchedule.setText(preferences.getCaseGroup(this));
		}else {
			spTypeSchedule.setText("");
			spTypeSchedule.setOnClickListener(this);
		}
		
		
		spTimeHours.setText("");
		spTimeMinute.setText("");
		spDateTime.setText("");
		spHospital.setText("");
		etExtrasInfo.setText("");
		etTechniquesRequirement.setText("");
		etPrice.setText("");
		etRoom.setText("");
		etFalculty.setText("");
		etRoom.setTextColor(context.getResources().getColor(R.color.black));
		etFalculty.setTextColor(context.getResources().getColor(R.color.black));
		btSentRequirement.setBackgroundResource(R.drawable.bg_btn_send_req);
		btSentRequirement.setText(context.getResources().getString(R.string.btn_send_req));
		ckbHigh.setChecked(false);
		ckbLow.setChecked(false);
		ckbMedium.setChecked(false);
		etNameScheldule.requestFocus();
		if(preferences.getTypeKeyUser(context)== 3){
			spDoctor.setBackgroundResource(R.drawable.bg_edt_selector);
		}
		btSentRequirement.setEnabled(true);
		btSentRequirement.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {//click gui yeu cau
				setDataForm();
				getDataForm();
				SchedUserRole_id =Case_id;
				if(listHospital != null){
					Calendar c = Calendar.getInstance();
					String timeSystem = c.get(Calendar.DAY_OF_MONTH)+ "-" + c.get(Calendar.MONTH + 1)+"-"+c.get(Calendar.YEAR);
					String timeCompare = spDateTime.getText().toString();
					int checktime= 0;
					if(!timeSystem.equals("") && timeSystem != null && !timeCompare.equals("") && timeCompare != null){
						checktime = StringUtilities.compareDate(timeSystem, timeCompare);
					}
					if(preferences.getTypeKeyUser(context) == 3){ // neu  thang dang nhap la thang bac si 
						User_id = Integer.parseInt(preferences.getUserID(context));
					}
					if (preferences.getUserAuthKey(context).equals(null)
							|| etNameScheldule.getText().toString().equals("")
							|| strTime.equals("") || Hospital_id == 0 || level == 0 || Case_id == 0
							|| SchedUserRole_id == 0 || checktime == 0 || User_id == 0) {
						if(preferences.getUserAuthKey(context).equals(null)){  //khong thanh cong
							Toast.makeText(context, context.getResources().getString(R.string.not_login), Toast.LENGTH_SHORT).show();
							return;
						}
						if(etNameScheldule.getText().toString().equals("")){
							Toast.makeText(context, context.getResources().getString(R.string.not_input_schedule), Toast.LENGTH_SHORT).show();
							return;
						}
						if(Case_id == 0){
							Toast.makeText(context, context.getResources().getString(R.string.not_input_type_schedule), Toast.LENGTH_SHORT).show();
							return;
						}
						if(strTime.equals("")){
							Toast.makeText(context, context.getResources().getString(R.string.not_input_time), Toast.LENGTH_SHORT).show();
							return;
						}
						if(Hospital_id == 0){
							Toast.makeText(context, context.getResources().getString(R.string.not_input_hopital), Toast.LENGTH_SHORT).show();
							return;
						}
						if(level == 0){
							Toast.makeText(context, context.getResources().getString(R.string.not_input_level), Toast.LENGTH_SHORT).show();
							return;
						}
						if(checktime != 2){
							Toast.makeText(context, context.getResources().getString(R.string.time_schedule_after_time_system), Toast.LENGTH_SHORT).show();
							return;
						}
						if(User_id == 0){
							Toast.makeText(context, context.getResources().getString(R.string.eror_input_doctor), Toast.LENGTH_SHORT).show();
							return;
						}
					} else { // thanh cong //khi ma thanh cong thi chuyen sang List thuc hien duoi listener
							btSentRequirement.setEnabled(false);
						try {
							testCreateSchedule(preferences.getUserAuthKey(context),
									"01022012123123", etNameScheldule.getText().toString(), User_id,
									strTime, strPrice, Hospital_id, strAddress, strRequire,
									level, Case_id,strAddInfos,strTypeCost, SchedUserRole_id);
						} catch (Exception e) {
							Log.e("BUG CREATE SCHEDULE", e.toString()+" .");
						}
					}
				}
			}
		});
	}
	private int getUserID(int position) {
		BMSUserModel bmsUserModel = new BMSUserModel();
		bmsUserModel = listUser.get(position);
		int User_id = Integer.parseInt(bmsUserModel.getUserID());
		return User_id;
	}
	private String getHopitalID(int position){
		Hospital hospital = new Hospital();
		hospital = listHospital.get(position);
		String HospitalID = hospital.getId();
		return HospitalID;
	}
	
	private int getCaseID(int position){
		Schedule schedule = new Schedule();
		schedule = listSchedule.get(position);
		int Case_id = schedule.getId();
		return Case_id;
	}
	
	private String getTechnicalID(int position){
		BMSUserModel bmsUserModel = new BMSUserModel();
		bmsUserModel = listTechniques.get(position);
		String technicalID = bmsUserModel.getUserID();
		return technicalID;
	}
	
	private void scheduleCompleteorCancel(String title) {//5
		showHideViewHead(false);
		showHideViewBackgroundEditText(false);
		showHideViewBotton(true);
		scheduleCompleteEnable(false);
		tvSurgeryReady.setText(title);
		btApprove.setVisibility(View.GONE);
		btCancelSchedule1.setVisibility(View.GONE);
		etnameTechChange.setVisibility(View.GONE);
		iconDeleteChange.setVisibility(View.GONE);
		btAdditionalRequirement.setVisibility(View.GONE);
		btKeySchelde.setVisibility(View.GONE);
		btCancelSchelde.setVisibility(View.GONE);
		tvWriteRate.setVisibility(View.GONE);
		etTittleRate.setVisibility(View.GONE);
		etContentRate.setVisibility(View.GONE);
		btSendRate.setVisibility(View.GONE);
		btSentRequirement.setVisibility(View.GONE);
		lvListTechnical.setEnabled(false);
		etTittleRate.setVisibility(View.VISIBLE);
		etContentRate.setVisibility(View.VISIBLE);
		etTittleRate.setEnabled(true);
		etContentRate.setEnabled(true);
		btSendRate.setEnabled(true);
		btSendRate.setVisibility(View.VISIBLE);
		test = 1;
	}
	
	private void scheduleReady() {//3		
		showHideViewHead(false);
		showHideViewBackgroundEditText(false);
		showHideViewBotton(true);
		spAddTechChange.setVisibility(View.VISIBLE);
		btAddIconChange.setVisibility(View.VISIBLE);
		btSentRequirement.setVisibility(View.GONE);
		tvSurgeryReady.setText(context.getResources().getString(R.string.surgery_ready));
		btPreparation.setVisibility(View.GONE);
		btCancelScheldules.setVisibility(View.GONE);
		btApprove.setVisibility(View.GONE);
		btCancelSchedule1.setVisibility(View.GONE);
		etnameTechChange.setVisibility(View.GONE);
		iconDeleteChange.setVisibility(View.GONE);
		listCommentAdapter = new ListCommentAdapter(context, listComment);
		lvComment.setAdapter(listCommentAdapter);
		UtilityListView.setListViewHeightBasedOnChildrenforListTest(context, lvComment);
		btKeySchelde.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) { //hoan thanh lich mo!!!
				pg_load.setVisibility(View.VISIBLE);
				Status = "5";
				BMSCore.getInstance(context).taskSentStatusSchedule(itemSergeryModel.getSurgeryId(), Status, preferences.getUserAuthKey(context), mListener);
			}
		});
		btCancelSchelde.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) { //huy lich mo
				pg_load.setVisibility(View.VISIBLE);
				Status = "4";
				BMSCore.getInstance(context).taskSentStatusSchedule(itemSergeryModel.getSurgeryId(), Status, preferences.getUserAuthKey(context), mListener);
			}
		});
	}
	
	
	private void confirmAndSort() {//2
		showHideViewHead(false);
		showHideViewBackgroundEditText(false);
		showHideViewBotton(false);
		tvSurgeryReady.setText(context.getResources().getString(R.string.start_schedule));
		btApprove.setVisibility(View.GONE);
		btSentRequirement.setVisibility(View.GONE);
		btCancelSchedule1.setVisibility(View.GONE);
		tvListTechnical.setVisibility(View.VISIBLE);
		lvListTechnical.setVisibility(View.VISIBLE);
		spAddTechChange.setVisibility(View.VISIBLE);
		btAddIconChange.setVisibility(View.VISIBLE);
		tvNameCreator.setText(StringUtilities.convertNamePeople(getPeopleCreator()));
		if(itemDetail != null ){
			tvSurgery.setText(itemDetail.getName());
			tvNameDoctor1.setText(StringUtilities.convertNamePeople(itemDetail.getFullname()));
			tvTypeSchedule1.setText(itemDetail.getCase_name());
		}
	
		btPreparation.setVisibility(View.VISIBLE);
		btCancelScheldules.setVisibility(View.VISIBLE);
		btPreparation.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {//click chuan bi xong
				showHideViewBotton(true);
				tvSurgeryReady.setText(context.getResources().getString(R.string.surgery_ready));
				btPreparation.setVisibility(View.GONE);
				btCancelScheldules.setVisibility(View.GONE);
				btApprove.setVisibility(View.GONE);
				btCancelSchedule1.setVisibility(View.GONE);
				etnameTechChange.setVisibility(View.GONE);
				iconDeleteChange.setVisibility(View.GONE);
				listCommentAdapter = new ListCommentAdapter(context, listComment);
				lvComment.setAdapter(listCommentAdapter);
				UtilityListView.setListViewHeightBasedOnChildrenforListTest(context, lvComment);
				pg_load.setVisibility(View.VISIBLE);
				Status = "3";//thai doi trang thai lich mo.. len trang thai 3
				BMSCore.getInstance(context).taskSentStatusSchedule(itemSergeryModel.getSurgeryId(), Status, preferences.getUserAuthKey(context), mListener);
				btKeySchelde.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {  //click hoan thanh
						Status = "5";
						pg_load.setVisibility(View.VISIBLE);
						BMSCore.getInstance(context).taskSentStatusSchedule(itemSergeryModel.getSurgeryId(), Status, preferences.getUserAuthKey(context), mListener);
						scheduleCompleteEnable(false);
					}
				});
				btCancelSchelde.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) { //click huy lich mo
						Status = "4";
						pg_load.setVisibility(View.VISIBLE);
						BMSCore.getInstance(context).taskSentStatusSchedule(itemSergeryModel.getSurgeryId(), Status, preferences.getUserAuthKey(context), mListener);
					}
				});
			}
		});
		btCancelScheldules.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {  //click huy lich mo
				Status = "4";
				pg_load.setVisibility(View.VISIBLE);
				BMSCore.getInstance(context).taskSentStatusSchedule(itemSergeryModel.getSurgeryId(), Status, preferences.getUserAuthKey(context), mListener);
			}
		});
	lvListTechnical.setVisibility(View.VISIBLE);
	}
	
	private void waitingConfirm() {//1
		showHideViewHead(false);
		showHideViewBackgroundEditText(false);
		showHideViewBotton(false);
		btSentRequirement.setVisibility(View.GONE);
		btApprove.setVisibility(View.VISIBLE);
		btCancelSchedule1.setVisibility(View.VISIBLE);
		lvComment.setVisibility(View.VISIBLE);
		etTittleRate.setVisibility(View.VISIBLE);
		etContentRate.setVisibility(View.VISIBLE);
		etTittleRate.setEnabled(true);
		etContentRate.setEnabled(true);
		btSendRate.setEnabled(true);
		tvWriteRate.setVisibility(View.VISIBLE);
		vComment.setVisibility(View.VISIBLE);
		btSendRate.setVisibility(View.VISIBLE);
		if(listTechniques.size() != 0 || listTechniques != null){
			tvListTechnical.setVisibility(View.VISIBLE);
		} else {
			tvListTechnical.setVisibility(View.GONE);
		}
		tvSurgeryReady.setText(context.getResources().getString(R.string.waiting_confirm));
		btApprove.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {//click xac nhan 
				/*
				 * click xac nhan thi chuyen lich mo sang trang thai xac nhan
				 */
				pg_load.setVisibility(View.VISIBLE);
				Status = "2";
				BMSCore.getInstance(context).taskSentStatusSchedule(itemSergeryModel.getSurgeryId(), Status, preferences.getUserAuthKey(context), mListener);
				tvSurgeryReady.setText(context.getResources().getString(R.string.start_schedule));
				btApprove.setVisibility(View.GONE);
				btCancelSchedule1.setVisibility(View.GONE);
				tvListTechnical.setVisibility(View.VISIBLE);
				lvListTechnical.setVisibility(View.VISIBLE);
				spAddTechChange.setVisibility(View.VISIBLE);
				btAddIconChange.setVisibility(View.VISIBLE);
			
				btPreparation.setVisibility(View.VISIBLE);
				btCancelScheldules.setVisibility(View.VISIBLE);
				btPreparation.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {//click chuan bi xong
						showHideViewBotton(true);
						tvSurgeryReady.setText(context.getResources().getString(R.string.surgery_ready));
						btPreparation.setVisibility(View.GONE);
						btCancelScheldules.setVisibility(View.GONE);
						btApprove.setVisibility(View.GONE);
						btCancelSchedule1.setVisibility(View.GONE);
						etnameTechChange.setVisibility(View.GONE);
						iconDeleteChange.setVisibility(View.GONE);
						listCommentAdapter = new ListCommentAdapter(context, listComment);
						lvComment.setAdapter(listCommentAdapter);
						UtilityListView.setListViewHeightBasedOnChildrenforListTest(context, lvComment);
						pg_load.setVisibility(View.VISIBLE);
						Status = "3";//thai doi trang thai lich mo.. len trang thai 3
						BMSCore.getInstance(context).taskSentStatusSchedule(itemSergeryModel.getSurgeryId(), Status, preferences.getUserAuthKey(context), mListener);
//						btAdditionalRequirement.setOnClickListener(this)
						btKeySchelde.setOnClickListener(new OnClickListener() {
							@Override
							public void onClick(View v) {
								pg_load.setVisibility(View.VISIBLE);
								Status = "5";//thai doi trang thai lich mo.. len trang thai 5
								BMSCore.getInstance(context).taskSentStatusSchedule(itemSergeryModel.getSurgeryId(), Status, preferences.getUserAuthKey(context), mListener);
							
							}
						});
						btCancelSchelde.setOnClickListener(new OnClickListener() {
							@Override
							public void onClick(View v) {
								pg_load.setVisibility(View.VISIBLE);
								Status = "4";//thai doi trang thai lich mo.. len trang thai 4
								BMSCore.getInstance(context).taskSentStatusSchedule(itemSergeryModel.getSurgeryId(), Status, preferences.getUserAuthKey(context), mListener);
							}
						});
					}
				});
				btCancelScheldules.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {  //click huy lich mo
						pg_load.setVisibility(View.VISIBLE);
						Status = "4";//thai doi trang thai lich mo.. len trang thai 4 huy lich mo
						BMSCore.getInstance(context).taskSentStatusSchedule(itemSergeryModel.getSurgeryId(), Status, preferences.getUserAuthKey(context), mListener);
//						ListSurgeryActivity.actionLaunch(context);
					}
				});
			}
		});
		btCancelSchedule1.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {//click huy lich mo
				pg_load.setVisibility(View.VISIBLE);
				Status = "4";//thai doi trang thai lich mo.. len trang thai 4 huy lich mo
				BMSCore.getInstance(context).taskSentStatusSchedule(itemSergeryModel.getSurgeryId(), Status, preferences.getUserAuthKey(context), mListener);
//				ListSurgeryActivity.actionLaunch(context);
			}
		});
	}
	
	private void scheduleCompleteEnable(Boolean check){
		if (!check) {
			etRoom.setEnabled(false);
			etFalculty.setEnabled(false);
			etExtrasInfo.setEnabled(false);
			etnameTechChange.setEnabled(false);
			etTechniquesRequirement.setEnabled(false);
			etPrice.setEnabled(false); 
//			etNameScheldule.setEnabled(false);
			spCreator.setEnabled(false);
			spDoctor.setEnabled(false);
//			spTypeSchedule.setEnabled(false);
			spTimeHours.setEnabled(false);
			spTimeMinute.setEnabled(false);
			spCurrentcy.setEnabled(false);
			spHospital.setEnabled(false);
			spDateTime.setEnabled(false);
			btAddIconChange.setEnabled(false);
			spAddTechChange.setEnabled(false);
			tvCreator.setEnabled(false);
			tvNameCreator.setEnabled(false);
			tvNameSchedule.setEnabled(false);
			tvSurgery.setEnabled(false);
			tvNameDoctor.setEnabled(false);
			tvNameDoctor1.setEnabled(false);
			tvTypeSchedule.setEnabled(false);
			tvTypeSchedule1.setEnabled(false);
			btAdditionalRequirement.setEnabled(false);
			btKeySchelde.setEnabled(false);
			btCancelSchelde.setEnabled(false);
			iconDeleteChange.setEnabled(false);
			btSentRequirement.setEnabled(false);
			btApprove.setEnabled(false);
			btCancelSchedule1.setEnabled(false);
			btPreparation.setEnabled(false);
			btCancelScheldules.setEnabled(false);
			lvListTechnical.setEnabled(false);
			lvComment.setEnabled(false);
			ckbLow.setEnabled(false);
			ckbMedium.setEnabled(false);
			ckbHigh.setEnabled(false);
			titleBelow.setEnabled(false);
			tvStatusSchedule.setEnabled(false);
			tvSurgeryReady.setEnabled(false);
		} else {
			etRoom.setEnabled(true);
			etFalculty.setEnabled(true);
			etExtrasInfo.setEnabled(true);
			etnameTechChange.setEnabled(true);
			etTechniquesRequirement.setEnabled(true);
			etPrice.setEnabled(true); 
			etTittleRate.setEnabled(true);
			etContentRate.setEnabled(true);
			etNameScheldule.setEnabled(true);
			spCreator.setEnabled(true);
			spDoctor.setEnabled(true);
			spTypeSchedule.setEnabled(true);
			spTimeHours.setEnabled(true);
			spTimeMinute.setEnabled(true);
			spCurrentcy.setEnabled(true);
			spHospital.setEnabled(true);
			spDateTime.setEnabled(true);
			btAddIconChange.setEnabled(true);
			spAddTechChange.setEnabled(true);
			tvCreator.setEnabled(true);
			tvNameCreator.setEnabled(true);
			tvNameSchedule.setEnabled(true);
			tvSurgery.setEnabled(true);
			tvNameDoctor.setEnabled(true);
			tvNameDoctor1.setEnabled(true);
			tvTypeSchedule.setEnabled(true);
			tvTypeSchedule1.setEnabled(true);
			btAdditionalRequirement.setEnabled(true);
			btKeySchelde.setEnabled(true);
			btCancelSchelde.setEnabled(true);
			iconDeleteChange.setEnabled(true);
			btSendRate.setEnabled(true);
			btSentRequirement.setEnabled(true);
			btApprove.setEnabled(true);
			btCancelSchedule1.setEnabled(true);
			btPreparation.setEnabled(true);
			btCancelScheldules.setEnabled(true);
			lvListTechnical.setEnabled(true);
			lvComment.setEnabled(true);
			ckbLow.setEnabled(true);
			ckbMedium.setEnabled(true);
			ckbHigh.setEnabled(true);
			titleBelow.setEnabled(true);
			tvStatusSchedule.setEnabled(true);
			tvSurgeryReady.setEnabled(true);
		}
	}
	/*
	 * get nguoi tao
	 */
	private String getPeopleCreator() {
		String peopleCreator = "";
		pg_load.setVisibility(View.VISIBLE);
		BMSCore.getInstance(context).taskGetDetailSergery(itemSergeryModel.getSurgeryId(), preferences.getUserAuthKey(context), mListener);
		for (int i = 0; i < itemDetailListUserRelatedModel.size(); i++) {
			if(itemDetailListUserRelatedModel.get(i).getActivity_id().equals("1")){
				peopleCreator = StringUtilities.convertNamePeople(itemDetailListUserRelatedModel.get(i).getFullname());
			}
		}
		return peopleCreator;
	}
	
	private void initView() {
		dateTime = new DateTimeSystem();
		etRoom = (EditText) findViewById(R.id.room);
		etFalculty = (EditText) findViewById(R.id.falculty);
		spHospital = (Button) findViewById(R.id.hospital);
		spHospital.setOnClickListener(this);
		etExtrasInfo = (EditText) findViewById(R.id.edt_extra_info);
		etTechniquesRequirement = (EditText) findViewById(R.id.edt_technic_req);
		etPrice = (EditText) findViewById(R.id.price);
		etTittleRate = (EditText) findViewById(R.id.tittle_rate);
		etContentRate = (EditText) findViewById(R.id.content_rate);
		etNameScheldule = (EditText) findViewById(R.id.edt_name_schedule);
		etnameTechChange = (EditText) findViewById(R.id.name_tech_change);
		spCreator = (Button) findViewById(R.id.spn_creator);
		spCreator.setText(StringUtilities.convertNamePeople(preferences.getUserLoginFullName(context)));
		spCreator.setOnClickListener(this);
		spDoctor = (Button) findViewById(R.id.spn_doctor);
		spDoctor.setOnClickListener(this);
		spTypeSchedule = (Button) findViewById(R.id.spn_type_schedule);
//		spTypeSchedule.setOnClickListener(this);
		spTimeHours = (Button) findViewById(R.id.spn_time_hours);
		spTimeHours.setHint(dateTime.getHOUR()+" "+getResources().getString(R.string.hour));
		spTimeHours.setOnClickListener(this);
		spTimeMinute = (Button) findViewById(R.id.spn_time_minutes);
		spTimeMinute.setHint(dateTime.getMINUTE()+" "+getResources().getString(R.string.minute));
		spTimeMinute.setOnClickListener(this);
		spDateTime = (Button) findViewById(R.id.et_date_time);
		spDateTime.setHint(dateTime.getDATE()+"-"+dateTime.getMONTH()+"-"+dateTime.getYEAR());
		spDateTime.setOnClickListener(this);
		spCurrentcy = (Button) findViewById(R.id.spn_currency);
		spCurrentcy.setOnClickListener(this);
		tvSurgeryReady = (TextView) findViewById(R.id.surgery_ready);
		tvCreator = (TextView) findViewById(R.id.txt_creator);
		tvCreator.setText(Html.fromHtml(getString(R.string.txt_creator) + " "
				+ "<font color=" + getResources().getColor(R.color.orange)
				+ ">*</font>"));
		tvNameCreator = (TextView) findViewById(R.id.name_creators);
		tvNameSchedule = (TextView) findViewById(R.id.txt_name_schedule);
		tvNameSchedule
				.setText(Html
						.fromHtml(getString(R.string.txt_name_schedule) + " "
								+ "<font color="
								+ getResources().getColor(R.color.orange)
								+ ">*</font>"));
		tvSurgery = (TextView) findViewById(R.id.name_surgery);
		tvNameDoctor = (TextView) findViewById(R.id.txt_name_doctor);
		tvNameDoctor.setText(Html.fromHtml(getString(R.string.txt_name_doctor)
				+ " " + "<font color="
				+ getResources().getColor(R.color.orange) + ">*</font>"));
		tvNameDoctor1 = (TextView) findViewById(R.id.name_doctor);
		tvTypeSchedule = (TextView) findViewById(R.id.txt_type_schedule);
		tvTypeSchedule
				.setText(Html
						.fromHtml(getString(R.string.txt_type_schedule) + " "
								+ "<font color="
								+ getResources().getColor(R.color.orange)
								+ ">*</font>"));
		tvTypeSchedule1 = (TextView) findViewById(R.id.type_schedule);
		tvTime = (TextView) findViewById(R.id.txt_time);
		tvTime.setText(Html.fromHtml(getString(R.string.txt_time_schedule)
				+ " " + "<font color="
				+ getResources().getColor(R.color.orange) + ">*</font>"));
		tvTimeDate = (TextView) findViewById(R.id.txt_time_date);
		tvTimeDate
				.setText(Html
						.fromHtml(getString(R.string.txt_date_time_schedule)
								+ " " + "<font color="
								+ getResources().getColor(R.color.orange)
								+ ">*</font>"));
		tvPlace = (TextView) findViewById(R.id.txt_place);
		tvPlace.setText(Html.fromHtml(getString(R.string.txt_place_schedule)
				+ " " + "<font color="
				+ getResources().getColor(R.color.orange) + ">*</font>"));
		tvLevelPriority = (TextView) findViewById(R.id.txt_level_priority);
		tvLevelPriority
				.setText(Html
						.fromHtml(getString(R.string.txt_level_priority) + " "
								+ "<font color="
								+ getResources().getColor(R.color.orange)
								+ ">*</font>"));
		tvListTechnical = (TextView) findViewById(R.id.txt_list);
		tvWriteRate = (TextView) findViewById(R.id.write_rate);
		btAdditionalRequirement = (Button) findViewById(R.id.additional_requirement);
		btAdditionalRequirement.setOnClickListener(this);
		btKeySchelde = (Button) findViewById(R.id.key_schelde);
		btCancelSchelde = (Button) findViewById(R.id.cancel_schelde);
		btSendRate = (Button) findViewById(R.id.send_rate);
		btSendRate.setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(View v) { // click giui danh gia
			DateTimeSystem dateTimeSystem = new DateTimeSystem();
			String Comment_date = dateTimeSystem.getDateMonthYear();
			if(!etContentRate.getText().toString().equals(null) && !etContentRate.getText().toString().equals("")){
				pg_load.setVisibility(View.VISIBLE);
				BMSCore.getInstance(context).taskSendComment(itemDetail.getID(),etContentRate.getText().toString(),
						etTittleRate.getText().toString(), Comment_date,preferences.getUserAuthKey(context), mListener);
			} else {
				Toast.makeText(context, ""+context.getResources().getString(R.string.not_content_rate), Toast.LENGTH_SHORT).show();
			}
		}
		});
		btSentRequirement = (Button) findViewById(R.id.send_requirement);
		iconDeleteChange = (Button) findViewById(R.id.icon_delete_change);
		btApprove = (Button) findViewById(R.id.approve);
		btCancelSchedule1 = (Button) findViewById(R.id.cancel_schedule1);
		btPreparation = (Button) findViewById(R.id.preparation);
		btCancelScheldules = (Button) findViewById(R.id.cancel_scheldule_);
		lvListTechnical = (ListView) findViewById(R.id.list_tech);
		lvComment = (ListView) findViewById(R.id.lv_comment);
		ibTittleBack = (ImageButton) findViewById(R.id.btn_tittle_back);
		ibTittleBack.setOnClickListener(this);
		ibTitleLogin = (ImageButton) findViewById(R.id.btn_title_login);
		ibTitleLogin.setBackgroundResource(Utils.getLogobyPermission(type));
		ibTitleLogin.setOnClickListener(this);
		ibAddSchedule = (ImageButton) findViewById(R.id.btn_add_schedule);
		ibAddSchedule.setOnClickListener(this);
		ibViewListSchedule = (ImageButton) findViewById(R.id.btn_view_list_schedule);
		ibViewListSchedule.setOnClickListener(this);
		titleBelow = (ImageButton) findViewById(R.id.btn_sub_tittle);
		tvStatusSchedule = (TextView) findViewById(R.id.tv_sub_title_name);
		tvComment = (TextView) findViewById(R.id.comment);
		vDashComment = (View) findViewById(R.id.dash_comment);
		vComment = (View) findViewById(R.id.v_comment);
		rl_reason = (RelativeLayout) findViewById(R.id.reasonrl);
		ckbLow = (CheckBox) findViewById(R.id.ckb_low);
		ckbLow.setOnCheckedChangeListener(this);
		ckbMedium = (CheckBox) findViewById(R.id.ckb_medium);
		ckbMedium.setOnCheckedChangeListener(this);
		ckbHigh  = (CheckBox) findViewById(R.id.ckb_high); 
		ckbHigh.setOnCheckedChangeListener(this);
		spAddTechChange = (Button) findViewById(R.id.add_tech_change);
		spAddTechChange.setOnClickListener(this);
		btAddIconChange = (Button) findViewById(R.id.add_icon_change);
		btAddIconChange.setOnClickListener(this);
		pg_load = (ProgressBar) findViewById(R.id.pg_load);
		btPoseNotParticipate = (Button) findViewById(R.id.pose_not_participate);
		titleBelow.setBackgroundResource(R.drawable.icon_create_tab);
		tvTitleName = (TextView) findViewById(R.id.tv_title_name);
		tvTitleName.setOnClickListener(this);
		if(preferences.getTypeKeyUser(context) == 2 || preferences.getTypeKeyUser(context) == 5){
			ibAddSchedule.setVisibility(View.INVISIBLE);
		}
		viewCommentAll = (Button) findViewById(R.id.view_comment_all);
		viewCommentAll.setOnClickListener(this);
	} 
	private void setDataForm() {
		spCreator.setText(StringUtilities.convertNamePeople(preferences.getUserLoginFullName(context)));   // nguoi tao
		GroupId = 3;
		pg_load.setVisibility(View.VISIBLE);
		BMSCore.getInstance(context).taskGetTypeUser(preferences.getUserAuthKey(context), GroupId,PAGE_LIMIT,pageNumberDoctor, mListener); //ten bac si
		pg_load.setVisibility(View.VISIBLE);
		BMSCore.getInstance(context).taskGetSchedule(preferences.getUserAuthKey(context), mListener);//loai benh an
		pg_load.setVisibility(View.VISIBLE);
		BMSCore.getInstance(context).taskGetHopital(preferences.getUserAuthKey(context), mListener);//danh sach benh vien
		//lay ra danh sach ky thuat vien phu trach
		GroupId = 2;
		pg_load.setVisibility(View.VISIBLE);
		BMSCore.getInstance(context).taskGetTypeUser(preferences.getUserAuthKey(context), GroupId,PAGE_LIMIT,pageNumberDoctor, mListener); 
		if(itemSergeryModel != null){
			String Schedule_id = itemSergeryModel.getSurgeryId();
			pg_load.setVisibility(View.VISIBLE);
			BMSCore.getInstance(context).taskGetComment(preferences.getUserAuthKey(context), Schedule_id, pageLimit, pageNumber, mListener);
		}
		
	}
	private void testCreateSchedule(String authenKey, String code, String name,int User_id,
			String Execute_date, String Price, int Hospital_id, String Address,
			String Require, int Level, int Case_id,String AddInfos,String TypeCost, int SchedUserRole_id) {
		pg_load.setVisibility(View.VISIBLE);
		BMSCore.getInstance(context).taskCreateSchedule(authenKey, code, name,User_id, Execute_date, Price, Hospital_id, Address, Require, Level, Case_id,AddInfos,TypeCost, SchedUserRole_id, mListener);
	}
	
	private void getDataForm() {
		if (!spCreator.getText().toString().equals("")) {
			spCreator.getText().toString().trim();
		} else {}
		if (!etNameScheldule.getText().toString().equals("")) {
			strNameSchedule = etNameScheldule.getText().toString().trim();
		} else {
			strNameSchedule = "";
		}
		if (!spDoctor.getText().toString().trim().equals("")) {
			strDoctor = spDoctor.getText().toString().trim();
		} else {
			strDoctor ="";
		}
		
		if (!spTypeSchedule.getText().toString().equals("")) {
			strTypeSchedule = spTypeSchedule.getText().toString().trim();
		} else {
			strTypeSchedule = "";
		}
		if (!spTimeHours.getText().toString().equals("")
				&& spTimeHours.getText().toString().length() >= 2
				&& !spTimeMinute.getText().toString().equals("")
				&& spTimeMinute.getText().toString().length() >= 2
				&& !spDateTime.getText().toString().equals("")) {
			strTime = convertTime(spDateTime.getText().toString().trim())+" "+spTimeHours.getText().toString().substring(0, 2).trim()
					+ ":"+ spTimeMinute.getText().toString().substring(0, 2).trim()+":00";
		} else {
			strTime = "";
		}
		if(!etRoom.getText().toString().equals("")){
			strRoom = etRoom.getText().toString().trim();
		} else { 
			strRoom = "";
		}
		if(!etFalculty.getText().toString().equals("")){
			strFalculty = etFalculty.getText().toString().trim();
		} else {
			strFalculty = "";
		}
		if(!strRoom.equals(null) && !strRoom.equals("") && strFalculty != null && !strFalculty.equals("")){
			strAddress = strRoom + " - "+ strFalculty;
		} else {
			strAddress = "";
		}
		if(!spHospital.getText().toString().equals("")){
			strHospital = spHospital.getText().toString().trim();
		} else {
			strHospital = "";	
		}
		if(!etExtrasInfo.getText().toString().equals("")){
			strExtrasInfo = etExtrasInfo.getText().toString().trim();
		} else {
			strExtrasInfo = "";
		}
		if(!etTechniquesRequirement.getText().toString().equals("")){
			etTechniquesRequirement.getText().toString().trim();
		} else {
		}
		if (!etTechniquesRequirement.getText().toString().equals("")) {
			strRequire = etTechniquesRequirement.getText().toString().trim();
		} else {
			strRequire = "";
		}
		if(!etPrice.getText().toString().equals("") && !spCurrentcy.getText().toString().equals("")){
			strPrice = etPrice.getText().toString().trim();
		} else {
			strPrice = "";
		}
		if(ckbHigh.isChecked()) {
			level = 3;
		} else if(ckbMedium.isChecked()) {
			level = 2;
		} else if(ckbLow.isChecked()){
			level = 1;
		}
		if(etExtrasInfo.getText().toString() != null){
			strAddInfos = etExtrasInfo.getText().toString().trim();
		} else { strAddInfos = "";}
		
		if(spCurrentcy.getText().toString() != null){
			strTypeCost =spCurrentcy.getText().toString();
		} else {
			strTypeCost = "";
			}
	}
	
	public static String convertTime(String DDMMYYYY) {
		SimpleDateFormat originalFormat = new SimpleDateFormat("dd-MM-yyyy");
		SimpleDateFormat targetFormat = new SimpleDateFormat("yyyy-MM-dd");
		Date date = null;
		try {
			date = originalFormat.parse(DDMMYYYY);
		} catch (ParseException ex) { }
		return targetFormat.format(date);
	}

	public static String convertDateTime(String dateReceivedFromUser)
			throws ParseException { // 2014-07-07 12:20:52 ==> 07/07/2014
		if (!dateReceivedFromUser.equals("")
				&& !dateReceivedFromUser.equals(null)) {
		}
		DateFormat userDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		DateFormat dateFormatNeeded = new SimpleDateFormat("dd-MM-yyyy");
		Date date = userDateFormat.parse(dateReceivedFromUser);
		String convertedDate = dateFormatNeeded.format(date);
		return convertedDate;
	}

	public static String convertDateTimeHourMinuteSecond(
			String dateReceivedFromUser) throws ParseException { // 2014-07-07 12:20:52 ==> 07/07/2014
		String convertedDate = "";
		if (!dateReceivedFromUser.equals("")
				&& !dateReceivedFromUser.equals(null)) {
			DateFormat userDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
			DateFormat dateFormatNeeded = new SimpleDateFormat(
					"dd-MM-yyyy hh:mm:ss");
			Date date = userDateFormat.parse(dateReceivedFromUser);
			convertedDate = dateFormatNeeded.format(date);
		}
		
		return convertedDate;
	}

	public static String convertHour(String dateReceivedFromUser)
			throws ParseException { // 2014-07-07 12:20:52 ==> 12
		String convertedDate="";
		if (!dateReceivedFromUser.equals("") && !dateReceivedFromUser.equals(null)) {
			DateFormat userDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			DateFormat dateFormatNeeded = new SimpleDateFormat("HH");
			Date date = userDateFormat.parse(dateReceivedFromUser);
			convertedDate = dateFormatNeeded.format(date);
			if (convertedDate.substring(0, 1).equals("0")) {
				convertedDate = convertedDate.substring(1);
			}
		}
		return convertedDate + " "+ (context.getResources().getString(R.string.hour));
	}

	public static String convertMinute(String dateReceivedFromUser)
			throws ParseException { // 2014-07-07 12:20:52 ==> 20
		String convertedDate = "";
		if (!dateReceivedFromUser.equals("") && !dateReceivedFromUser.equals(null)) {
			DateFormat userDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
			DateFormat dateFormatNeeded = new SimpleDateFormat("mm");
			Date date = userDateFormat.parse(dateReceivedFromUser);
			convertedDate = dateFormatNeeded.format(date);
			if (convertedDate.substring(0, 1).equals("0")) {
				convertedDate = convertedDate.substring(1);
			}
		}
		return convertedDate + " "+ (context.getResources().getString(R.string.minute));
	}
	private static String[] arrDoctor;
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.spn_creator:
			// getDataSpinner1();
			break;
		case R.id.spn_doctor:
			if (listUser != null && listUser.size() != 0) {
				arrDoctor = new String[listUser.size()];
				for (int i = 0; i < arrDoctor.length; i++) {
					arrDoctor[i] = StringUtilities.convertNamePeople(listUser
							.get(i).getFullName());
				}
				getDataSpinner1(arrDoctor, spDoctor, 1);
			}
			break;
		case R.id.spn_type_schedule:
			if(listSchedule != null && listSchedule.size() != 0){
				String[] arrSchedule = new String[listSchedule.size()];
				for (int i = 0; i < arrSchedule.length; i++) {
					arrSchedule[i] = listSchedule.get(i).getName();
				}
				getDataSpinner1(arrSchedule, spTypeSchedule,3);
			}
			break;
		
		case R.id.send_requirement:
			getDataForm();
			break;
		case R.id.spn_currency:
			String[] curentcy = getResources().getStringArray(R.array.currency);
			getDataSpinner1(curentcy, spCurrentcy,0);
			break;
		case R.id.spn_time_hours:
			String[] hours = new String[24];
			for (int i = 0; i < 24; i++) {
				if(i<10){
					hours[i] = "0"+i + " " + getResources().getString(R.string.hour);
				} else {
					hours[i] = i + " " + getResources().getString(R.string.hour);
				}
			}
			getDataSpinner1(hours, spTimeHours,0);
			break;
		case R.id.spn_time_minutes:
			String[] minute = new String[6];
			for (int i = 0; i < 6; i++) {
				if(i==0){
					minute[i] = "0"+(i * 10) + " " + getResources().getString(R.string.minute);
				} else {
					minute[i] = (i * 10) + " " + getResources().getString(R.string.minute);
				}
			}
			getDataSpinner1(minute, spTimeMinute,0);
			break;
		case R.id.hospital:
			if (listHospital != null && listHospital.size() != 0) {
				String[] arrHospital = new String[listHospital.size()];
				for (int i = 0; i < arrHospital.length; i++) {
					arrHospital[i] = listHospital.get(i).getName();
				}
				getDataSpinner1(arrHospital, spHospital, 2);
			}
			break;
		case R.id.btn_tittle_back:
//			if (action!= null && action.equals(ACTION_CREATE_SURGERY)){
				this.finish();
//			}
			break;
		case R.id.tv_title_name:
			HomeBMSActivity.actionLaunch(context);
			break;
		case R.id.btn_title_login:
			if(preferences.getUserAuthKey(context).equals("") ||preferences.getUserAuthKey(context).equals(null)){
				LoginBMSActivity.actionLaunch(getApplicationContext());
				String a=getApplicationContext().toString();
			} else {
				 LogoutDialog dialog = new LogoutDialog(context);
				 dialog.show();
			}
			break;
		case R.id.btn_view_list_schedule:
			if(preferences.getTypeKeyUser(context) != 3){
				finish();
			}
			ListSurgeryActivity.actionLaunchbyCreateSegery(context);
			break;
		case R.id.btn_add_schedule: // click title lich mo moi
			//reset lai 
			User_id = 0;
			Hospital_id = 0;
			Case_id = 0;
			SchedUserRole_id = 0;
			spDoctor.setEnabled(true);
			etRoom.setHint(context.getResources().getString(R.string.txt_room_schedule));
			etFalculty.setHint(context.getResources().getString(R.string.txt_falculty_schedule));
			spHospital.setHint(context.getResources().getString(R.string.select_name_hospital));
			etExtrasInfo.setHint(context.getResources().getString(R.string.edt_extra_info));
			etTechniquesRequirement.setHint(context.getResources().getString(R.string.txt_technic_req));
			etPrice.setHint(context.getResources().getString(R.string.txt_price_schedule));
			CreateScheduleAll();
			spCreator.setText(preferences.getUserLoginFullName(context));
			if(preferences.getTypeKeyUser(context) == 3){
				spDoctor.setText(preferences.getUserLoginFullName(context));
				spDoctor.setEnabled(false);
				spCurrentcy.setEnabled(true);
			}
			break;
		case R.id.et_date_time:
			getDefaultInfor();
			showDatePickerDialog(spDateTime);
			break;
		case R.id.view_comment_all:
			if(action.equals(ACTION_ITEM_SERGERY)){
				ViewAllCommentActivity.actionLaunch(context, itemSergeryModel);
			} else {
				ViewAllCommentActivity.actionLaunchID(context, itemDetail.getID());
			}
			
			break;
		case R.id.add_tech_change:
			if(listTechniques != null && listTechniques.size() != 0){
				String[] listtech = new String[listTechniques.size()];
				for (int i = 0; i < listTechniques.size(); i++) {
					listtech[i] = StringUtilities.convertNamePeople(listTechniques.get(i).getFullName());
				}
				getDataSpinner1(listtech, spAddTechChange,4);
			}
			break;
		case R.id.add_icon_change:
			if(!spAddTechChange.getText().toString().equals(null) && !spAddTechChange.getText().toString().equals("")){
				String Schedule_id = "";
				if(itemSergeryModel != null){
					Schedule_id = itemSergeryModel.getSurgeryId();
				}
				pg_load.setVisibility(View.VISIBLE);
				Log.e("technicalID", technicalID+" .");
				BMSCore.getInstance(context).taskAddTechnical(Schedule_id, technicalID, preferences.getUserAuthKey(context), mListener);
			} else if(spAddTechChange.getText().toString().equals(null) || spAddTechChange.getText().toString().equals("")){
				Toast.makeText(context, context.getResources().getString(R.string.select_add_tech), Toast.LENGTH_SHORT).show();
			}
			break;
		case R.id.additional_requirement://click sua lich mo
			showHideViewHead(true);
			showHideViewBackgroundEditText(true);
			String priceCustom = etPrice.getText().toString().split(" ")[0];
			String priceCustom1 = etPrice.getText().toString().split(" ")[1];
			etPrice.setText(priceCustom);
			spCurrentcy.setText(priceCustom1);
			etRoom.setTextColor(context.getResources().getColor(R.color.black));
			etFalculty.setTextColor(context.getResources().getColor(R.color.black));
			if(itemDetail != null){
				etNameScheldule.setText(itemDetail.getName()+"");
			}
			btAdditionalRequirement.setText(context.getResources().getString(R.string.write_change));
			btAdditionalRequirement.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {//click ghi lai thay doi
					getDataForm();
//					SchedUserRole_id = User_id = Integer.parseInt(preferences.getUserID(context));
					
					if(User_id == 0){// khi khong thay doi bac si
						User_id = Integer.parseInt(itemDetail.getUser_id());
					} else { //khi thay doi
//						User_id = gia tri ma khi thang sua lich mo thay doi
					}
					
					strNameSchedule = etNameScheldule.getText().toString().trim();
					strPrice = etPrice.getText().toString();
					strRequire = etTechniquesRequirement.getText().toString();
					strAddress = etRoom.getText().toString().trim() +" - "+ etFalculty.getText().toString().trim();
					strTime = convertTime(spDateTime.getText().toString().trim())+" "+spTimeHours.getText().toString().substring(0, 2).trim()
							+ ":"+ spTimeMinute.getText().toString().substring(0, 2).trim()+":00";
					Calendar c = Calendar.getInstance();
					String timeSystem = c.get(Calendar.DAY_OF_MONTH)+ "-" + c.get(Calendar.MONTH + 1)+"-"+c.get(Calendar.YEAR);
					String timeCompare = spDateTime.getText().toString();
					int checktime= 0;
					if(Case_id == 0){
						Case_id = Integer.parseInt(itemDetail.getCase_id());
					}
					if(Hospital_id == 0){
						Hospital_id = Integer.parseInt(itemDetail.getHospital_id());
					}
					if(!timeSystem.equals("") && timeSystem != null && !timeCompare.equals("") && timeCompare != null){
						checktime = StringUtilities.compareDate(timeSystem, timeCompare);
					}
					if (preferences.getUserAuthKey(context).equals(null) || etNameScheldule.getText().toString().equals("")
							|| strTime.equals("") || Hospital_id == 0 || level == 0 || Case_id == 0 || checktime != 2) {
						if(preferences.getUserAuthKey(context).equals(null)){  //khong thanh cong
							Toast.makeText(context, context.getResources().getString(R.string.not_login), Toast.LENGTH_SHORT).show();
							return;
						}
						if(etNameScheldule.getText().toString().equals("")){
							Toast.makeText(context, context.getResources().getString(R.string.not_input_schedule), Toast.LENGTH_SHORT).show();
							return;
						}
						if(strTime.equals("")){
							Toast.makeText(context, context.getResources().getString(R.string.not_input_time), Toast.LENGTH_SHORT).show();
							return;
						}
						if(Hospital_id == 0){
							Toast.makeText(context, context.getResources().getString(R.string.not_input_hopital), Toast.LENGTH_SHORT).show();
							return;
						}
						if(level == 0){
							Toast.makeText(context, context.getResources().getString(R.string.not_input_level), Toast.LENGTH_SHORT).show();
							return;
						}
						if(Case_id == 0){
							Toast.makeText(context, context.getResources().getString(R.string.not_input_type_schedule), Toast.LENGTH_SHORT).show();
							return;
						}
						if(checktime != 2){
							Toast.makeText(context, context.getResources().getString(R.string.time_schedule_after_time_system), Toast.LENGTH_SHORT).show();
							return;
						}
					} else {
						BMSCore.getInstance(context).taskUpdateAndroidSchedule(
								"LM01022012", strNameSchedule, strPrice, strTime,
								preferences.getUserAuthKey(context), Hospital_id,
								strAddress, level, Case_id, strAddInfos,
								SchedUserRole_id, strTypeCost,
								itemSergeryModel.getSurgeryId(), strRequire,
								User_id, mListener);
						}
				}
			}); 
			
			break;

		default:
			break;
		}
	}
	

	private void showDatePickerDialog(final Button button) {
		OnDateSetListener callback = new OnDateSetListener() {
			public void onDateSet(DatePicker view, int year, int monthOfYear,
					int dayOfMonth) {
				button.setText((dayOfMonth) + "-" + (monthOfYear + 1) + "-"
						+ year);
				cal.set(year, monthOfYear, dayOfMonth);
				dateFinish = cal.getTime();
			}

		};
		String s = button.getText() + "";
		String strArrtmp[] = s.split("-");
		int ngay = Integer.parseInt(strArrtmp[0]);
		int thang = Integer.parseInt(strArrtmp[1]) - 1;
		int nam = Integer.parseInt(strArrtmp[2]);
		DatePickerDialog pic = new DatePickerDialog(
				context, callback, nam, thang, ngay);
		pic.setTitle(getResources().getString(R.string.select_date_start));
		pic.show();
	}

	public void getDefaultInfor() {
		cal = Calendar.getInstance();
		SimpleDateFormat dft = null;
		dft = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault());
		String strDate = dft.format(cal.getTime());
		spDateTime.setText(strDate);
		dateFinish = cal.getTime();
	}
	
	class CreateScheduleListener extends BMSListener{
		@Override
		public void finishCreateSchedule(int returnCode, String resultMsg) {
			super.finishCreateSchedule(returnCode, resultMsg);
			switch (returnCode) {
			case 0: //fail
				showMessageToast(resultMsg);
				break;
			case 1: //tao lich mo thanh cong
				showMessageToast(resultMsg);
				runOnUiThread(new Runnable() {
					@SuppressLint("NewApi") @Override
					public void run() {
						ListSurgeryActivity.actionLaunch(context);  
					}
				});
				
				break;
			case 2:
				showMessageToast(resultMsg);
				break;
			case 3:
				showMessageToast(resultMsg);
				break;
			case 4:
				showMessageToast(resultMsg);
				break;

			default:
				break;
			}
			pg_load.setVisibility(View.GONE);
		}
		@Override
		public void finishGetTypeUsers(final int returnCode, String resultMsg, int recordNumber, int countPage,final int groupID, final ArrayList<BMSUserModel> listUserModel) {
			super.finishGetTypeUsers(returnCode, resultMsg, recordNumber, countPage,groupID,listUserModel);
			runOnUiThread(new Runnable() {
				@Override
				public void run() {
//					pg_load.setVisibility(View.VISIBLE);
					if (returnCode == IBMSProtocol.STATUS_CODE_OK){
						if(groupID == 3){// lay ra duoc thang ten bac si
							listUser = listUserModel;
						}
						if(groupID == 2){ //danh sach ca ki thuat vien
							listTechniques = listUserModel;
						}
					} else if (returnCode == IBMSProtocol.STATUS_CODE_GENERIC_FAIL){
						Toast.makeText(context, context.getResources().getString(R.string.error_hospital), Toast.LENGTH_SHORT).show();
					}else if (returnCode == IBMSProtocol.STATUS_CODE_GENERIC_FAIL_CONECTTION){
						Toast.makeText(context, context.getResources().getString(R.string.error_network_connection), Toast.LENGTH_SHORT).show();
					}
					pg_load.setVisibility(View.GONE);
				}
			});
		}
		
		@Override
		public void finishGetHopital(final int returnCode, String resultMsg, final ArrayList<Hospital> listHopital) {
			super.finishGetHopital(returnCode, resultMsg, listHopital);
			runOnUiThread(new Runnable() {
				@Override
				public void run() {
//					pg_load.setVisibility(View.VISIBLE);
					if (returnCode == IBMSProtocol.STATUS_CODE_OK){
						CreateScheduleActivity.this.listHospital = listHopital;
					}else if (returnCode == IBMSProtocol.STATUS_CODE_GENERIC_FAIL){
						Toast.makeText(context, context.getResources().getString(R.string.error_hospital), Toast.LENGTH_SHORT).show();
					}else if (returnCode == IBMSProtocol.STATUS_CODE_GENERIC_FAIL_CONECTTION){
						Toast.makeText(context, context.getResources().getString(R.string.error_network_connection), Toast.LENGTH_SHORT).show();
					}
					pg_load.setVisibility(View.GONE);
				}
			});
		}
		
		
		@Override
		public void finishGetSchedule(final int returnCode, String resultMsg, final ArrayList<Schedule> listSchedule) {
			super.finishGetSchedule(returnCode, resultMsg, listSchedule);
			runOnUiThread(new Runnable() {
				@Override
				public void run() {
//					pg_load.setVisibility(View.VISIBLE);
//					CreateScheduleActivity.this.listSchedule = listSchedule;
					if (returnCode == IBMSProtocol.STATUS_CODE_OK){
						CreateScheduleActivity.this.listSchedule = listSchedule;
					}else if (returnCode == IBMSProtocol.STATUS_CODE_GENERIC_FAIL){
						Toast.makeText(context, context.getResources().getString(R.string.error_schedule), Toast.LENGTH_SHORT).show();
					}else if (returnCode == IBMSProtocol.STATUS_CODE_GENERIC_FAIL_CONECTTION){
						Toast.makeText(context, context.getResources().getString(R.string.error_network_connection), Toast.LENGTH_SHORT).show();
					}
					pg_load.setVisibility(View.GONE);
				}
			});
		}
		
		@Override
		public void finishGetComment(final int returnCode, String resultMsg,int recordNumber, int countPage, final ArrayList<CommentModel> listComment) {
			super.finishGetComment(returnCode, resultMsg, recordNumber, countPage,listComment);
			runOnUiThread(new Runnable() {
				@Override
				public void run() {
//					pg_load.setVisibility(View.VISIBLE);
					if (returnCode == IBMSProtocol.STATUS_CODE_OK){
						ArrayList<CommentModel> arrListComment = new ArrayList<CommentModel>();
						if(listComment != null && listComment.size() != 0){
							CreateScheduleActivity.this.listComment = listComment;
							if(listComment.size() >= 3){
								arrListComment.add(listComment.get(0));
								arrListComment.add(listComment.get(1));
								arrListComment.add(listComment.get(2));
								viewCommentAll.setVisibility(View.VISIBLE);
							} else {
								arrListComment = listComment;
							}
							listCommentAdapter = new ListCommentAdapter(context, arrListComment);
							lvComment.setAdapter(listCommentAdapter);
							tvComment.setVisibility(View.VISIBLE);
							vDashComment.setVisibility(View.VISIBLE);
						} else {
							tvComment.setVisibility(View.GONE);
							vDashComment.setVisibility(View.GONE);
						}
						UtilityListView.setListViewHeightBasedOnChildrenforWarranty(context, lvComment);
						etTittleRate.setText(null);
						etContentRate.setText(null);
						
					}else if (returnCode == IBMSProtocol.STATUS_CODE_GENERIC_FAIL){
						Toast.makeText(context, context.getResources().getString(R.string.error_list_comment), Toast.LENGTH_SHORT).show();
					}else if (returnCode == IBMSProtocol.STATUS_CODE_GENERIC_FAIL_CONECTTION){
						Toast.makeText(context, context.getResources().getString(R.string.error_network_connection), Toast.LENGTH_SHORT).show();
					}
					pg_load.setVisibility(View.GONE);
				}
			});
		}
		
		
		@Override
		public void finishgetDetailSergery(final int returnCode, String resultMsg,
				final DetailSergeryModel itemDetail,
				final ArrayList<TechniciansModel> itemDetailTechniciansModel,
				final ArrayList<ListUserRelatedModel> itemDetailListUserRelatedModel) {
			super.finishgetDetailSergery(returnCode, resultMsg, itemDetail,itemDetailTechniciansModel, itemDetailListUserRelatedModel);
			runOnUiThread(new Runnable() {
				@Override
				public void run() {
//					pg_load.setVisibility(View.VISIBLE);
					if (returnCode == IBMSProtocol.STATUS_CODE_OK){
						CreateScheduleActivity.this.itemDetailTechniciansModel.clear();
						CreateScheduleActivity.this.itemDetailListUserRelatedModel.clear();
						CreateScheduleActivity.this.itemDetailTechniciansModel  = itemDetailTechniciansModel;
						CreateScheduleActivity.this.itemDetail = itemDetail;
						CreateScheduleActivity.this.itemDetailListUserRelatedModel = itemDetailListUserRelatedModel;
						for (int i = 0; i < itemDetailListUserRelatedModel.size(); i++) {  //nguoi tao
							if(itemDetailListUserRelatedModel.get(i).getActivity_id().equals("1")){
								tvNameCreator.setText(StringUtilities.convertNamePeople(itemDetailListUserRelatedModel.get(i).getFullname()+""));
								spCreator.setText(itemDetailListUserRelatedModel.get(i).getFullname()+"");
							}
						}
						tvSurgery.setText(itemDetail.getName()+""); //ten lich mo
						etNameScheldule.setText(itemDetail.getName()+"");
						tvNameDoctor1.setText(StringUtilities.convertNamePeople(itemDetail.getFullname())+""); //ten bac si
						spDoctor.setText(StringUtilities.convertNamePeople(itemDetail.getFullname())+""); 
						tvTypeSchedule1.setText(itemDetail.getCase_name()+"");  //loai lich mo
						spTypeSchedule.setText(itemDetail.getCase_name()+"");
						try {
							spDateTime.setText(convertDateTime(itemDetail.getExecute_date())+"");
						} catch (ParseException e) {
							Log.e("finishgetDetailSergery", e.toString());
							e.printStackTrace();
						}
						try {
							spTimeHours.setText(convertHour(itemDetail.getExecute_date())+"");
						} catch (ParseException e) {
							e.printStackTrace();
						}
						try {
							spTimeMinute.setText(convertMinute(itemDetail.getExecute_date())+"");
						} catch (Exception e) {
							e.printStackTrace();
						}
						String address = itemDetail.getAddress();
						if(address != null && !address.equals("")&& address.split(" - ") != null && address.split(" - ").length == 2){
							String[] room = address.split(" - ");
							etRoom.setText(room[0]+"");
							etFalculty.setText(room[1]+"");
							etRoom.setTextColor(context.getResources().getColor(R.color.hint_color));
							etFalculty.setTextColor(context.getResources().getColor(R.color.hint_color));
						} else {
							etRoom.setText("");
							etFalculty.setText("");
						}
						spHospital.setText(itemDetail.getHospital_name()+" ");
						etExtrasInfo.setText(itemDetail.getAddInfos()+" ");
						etTechniquesRequirement.setText(itemDetail.getRequire());
						spHospital.setHint(null);
						etExtrasInfo.setHint(null);
						etTechniquesRequirement.setHint(null);
						etPrice.setHint(null);
						etRoom.setHint(null);
						etFalculty.setHint(null);
						spHospital.setHint(null);
						spCurrentcy.setText(itemDetail.getTypeCost());
						if(itemDetail.getPrice().contentEquals(" ")){
							if(spCurrentcy.getVisibility() == View.VISIBLE){ 
								etPrice.setText(StringUtilities.convertPrice(itemDetail.getPrice().split(" ")[0]));
							} else {
								etPrice.setText(StringUtilities.convertPrice(itemDetail.getPrice().split(" ")[0]) + " "+ itemDetail.getTypeCost());
							}
						} else {
							if(spCurrentcy.getVisibility() == View.VISIBLE){ 
								etPrice.setText(StringUtilities.convertPrice(itemDetail.getPrice()));
							} else {
								etPrice.setText(StringUtilities.convertPrice(itemDetail.getPrice()) +" "+ itemDetail.getTypeCost());
							}
						}
						int level = Integer.parseInt(itemDetail.getLevel());
						setCheck(level);
						listTechnicalAdapter = new ListTechnicalAdapter(context, CreateScheduleActivity.this.itemDetailTechniciansModel);
						lvListTechnical.setAdapter(listTechnicalAdapter);
						lvListTechnical.setVisibility(View.VISIBLE);
						UtilityListView.setListViewHeightBasedOnChildrenforList(context, lvListTechnical);
						if(itemDetailTechniciansModel == null || itemDetailTechniciansModel.size() == 0){
							tvListTechnical.setVisibility(View.GONE);
						} else {
							tvListTechnical.setVisibility(View.VISIBLE);
						}
						spAddTechChange.setText(null); //khi nhan vao icon them ky thuat vien setText cho spinner nÃƒÂ y lÃƒÂ  null
						if(action.equals(ACTION_ID_SERGERY)){
							BMSCore.getInstance(context).taskGetComment(preferences.getUserAuthKey(context), itemDetail.getID(), "3", "1", mListener);
							btSentRequirement.setVisibility(View.GONE);
							scheduleStatus = Integer.parseInt(itemDetail.getSchedStt_id());//lay duoc trang thai cua lich mo
							if(preferences.getTypeKeyUser(context) == 3){  //doctor
								doctorViewSchedule();
								spAddTechChange.setVisibility(View.GONE);
								btAddIconChange.setVisibility(View.GONE);
							} else if(preferences.getTypeKeyUser(context) == 4){  //admin
								actionAdmin();
							} else if(preferences.getTypeKeyUser(context) == 1){ //maketing
								actionMaketing();
							} else if(preferences.getTypeKeyUser(context) == 2){ //ki thuat vien
								actionTechnical();
							}
							//luon hien thi phan comment khi vao action nay
							lvComment.setVisibility(View.VISIBLE);
							etTittleRate.setVisibility(View.VISIBLE);
							etContentRate.setVisibility(View.VISIBLE);
							tvWriteRate.setVisibility(View.VISIBLE);
							btSendRate.setVisibility(View.VISIBLE);
							if(listComment != null && listComment.size() != 0){
								tvComment.setVisibility(View.VISIBLE);
								vDashComment.setVisibility(View.VISIBLE);
							} else {
								tvComment.setVisibility(View.GONE);
								vDashComment.setVisibility(View.GONE);
							}
							switch (scheduleStatus) {
							case 5://hoan thanh
								scheduleCompleteorCancel(context.getResources().getString(R.string.surgery_complete));
								break;
							case 4://huy ca mo
								scheduleCompleteorCancel(context.getResources().getString(R.string.surgery_cancel));
								break;
							case 3://BMS san sang
								scheduleCompleteorCancel(context.getResources().getString(R.string.surgery_ready));
								break;
							case 2://BMS xac nhan va sap xep
								scheduleCompleteorCancel(context.getResources().getString(R.string.preparation_surgery));
								break;
							case 1://dang cho BMS xac nhan thang ki thuat vien khong co trang thai nay vi khi ở trang thai nay chua ai co quyen add ki thuat vien vao
								scheduleCompleteorCancel(context.getResources().getString(R.string.waiting_confirm));
								break;

							default:
								break;
							}
							tvWriteRate.setVisibility(View.VISIBLE);
							etPrice.setText(StringUtilities.convertPrice(itemDetail.getPrice()) +" "+ itemDetail.getTypeCost());
							setCheck(level);
						}
					}else if (returnCode == IBMSProtocol.STATUS_CODE_GENERIC_FAIL){
						Toast.makeText(context, context.getResources().getString(R.string.error_detail_sergery), Toast.LENGTH_SHORT).show();
					}else if (returnCode == IBMSProtocol.STATUS_CODE_GENERIC_FAIL_CONECTTION){
						Toast.makeText(context, context.getResources().getString(R.string.error_network_connection), Toast.LENGTH_SHORT).show();
					}
					
					
					pg_load.setVisibility(View.GONE);
				}
			});
		}
		
		@Override
		public void finishAddTechnical(final int returnCode, String resultMsg, String scheduleTechnicianID) {
			super.finishAddTechnical(returnCode, resultMsg, scheduleTechnicianID);
			runOnUiThread(new Runnable() {
				@Override
				public void run() {
//					pg_load.setVisibility(View.VISIBLE);
					if (returnCode == IBMSProtocol.STATUS_CODE_OK || returnCode == IBMSProtocol.STATUS_CODE_RECORD_NOT_FOUND){
						showMessageToast(context.getResources().getString(R.string.add_sussess));
						pg_load.setVisibility(View.VISIBLE);
						BMSCore.getInstance(context).taskGetDetailSergery(itemSergeryModel.getSurgeryId(), preferences.getUserAuthKey(context), mListener);
						spAddTechChange.setText(null); //khi nhan vao icon them ky thuat vien setText cho spinner   null
					} else if (returnCode == IBMSProtocol.STATUS_CODE_GENERIC_FAIL){
						Toast.makeText(context, context.getResources().getString(R.string.error_add_technical), Toast.LENGTH_SHORT).show();
						spAddTechChange.setText(null);
					}else if (returnCode == IBMSProtocol.STATUS_CODE_GENERIC_FAIL_CONECTTION){
						Toast.makeText(context, context.getResources().getString(R.string.error_network_connection), Toast.LENGTH_SHORT).show();
						spAddTechChange.setText(null);
					} else if(returnCode == IBMSProtocol.STATUS_CODE_EXIT_RECORD){
						showMessageToast(context.getResources().getString(R.string.tecnical_exits_records));
					}
					else {
						showMessageToast(context.getResources().getString(R.string.add_fail));
						spAddTechChange.setText(null); //khi nhan vao icon them ky thuat vien setText cho spinner   null
					}
					pg_load.setVisibility(View.GONE);
				}
			});
		}
		
		@Override
		public void finishSentStatusSchedule(final int returnCode, String resultMsg, final String status) {
			super.finishSentStatusSchedule(returnCode, resultMsg, status);
			runOnUiThread(new Runnable() {
				@Override
				public void run() {
//					pg_load.setVisibility(View.VISIBLE);
					if (returnCode == IBMSProtocol.STATUS_CODE_OK){
						switch (Integer.parseInt(status)) {
						case 5:
							showMessageToast(context.getResources().getString(R.string.schedule_status_5));
							ListSurgeryActivity.actionLaunch(context);
							break;
						case 4:
							showMessageToast(context.getResources().getString(R.string.schedule_status_4));
							ListSurgeryActivity.actionLaunch(context);
							break;
						case 3:
							showMessageToast(context.getResources().getString(R.string.schedule_status_3));
							break;
						case 2:
							showMessageToast(context.getResources().getString(R.string.schedule_status_2));
							break;
						case 1:
							showMessageToast(context.getResources().getString(R.string.schedule_status_1));
							break;
						default:
							showMessageToast(context.getResources().getString(R.string.change_fail));
							break;
						}
					}else if (returnCode == IBMSProtocol.STATUS_CODE_GENERIC_FAIL){
						Toast.makeText(context, context.getResources().getString(R.string.error_status_sergery), Toast.LENGTH_SHORT).show();
					}else if (returnCode == IBMSProtocol.STATUS_CODE_GENERIC_FAIL_CONECTTION){
						Toast.makeText(context, context.getResources().getString(R.string.error_network_connection), Toast.LENGTH_SHORT).show();
					} else {
						showMessageToast(context.getResources().getString(R.string.change_fail));
					}
					pg_load.setVisibility(View.GONE);
				}
			});
		}
		
		@Override
		public void finishSentComment(final int returnCode, String resultMsg) {
			super.finishSentComment(returnCode, resultMsg);
			runOnUiThread(new Runnable() {
				@Override
				public void run() {
//					pg_load.setVisibility(View.VISIBLE);
					if (returnCode == IBMSProtocol.STATUS_CODE_OK){
						showMessageToast(context.getResources().getString(R.string.sent_comment_sussess));
						pg_load.setVisibility(View.VISIBLE);
						BMSCore.getInstance(context).taskGetComment(preferences.getUserAuthKey(context), itemDetail.getID(), "10", "1", mListener);
					}else if (returnCode == IBMSProtocol.STATUS_CODE_GENERIC_FAIL){
						Toast.makeText(context, context.getResources().getString(R.string.error_comment), Toast.LENGTH_SHORT).show();
					}else if (returnCode == IBMSProtocol.STATUS_CODE_GENERIC_FAIL_CONECTTION){
						Toast.makeText(context, context.getResources().getString(R.string.error_network_connection), Toast.LENGTH_SHORT).show();
					} else {
						showMessageToast(context.getResources().getString(R.string.sent_comment_fail));
					}
					pg_load.setVisibility(View.GONE);
				}
			});
		}
		
		@Override
		public void finishPoseNotParticipate(final int returnCode, String resultMsg) {
			super.finishPoseNotParticipate(returnCode, resultMsg);
			runOnUiThread(new Runnable() {
				@Override
				public void run() {
//					pg_load.setVisibility(View.VISIBLE);
					if(returnCode == IBMSProtocol.STATUS_CODE_OK){
						btSentRequirement.setEnabled(false);
						showMessageToast(context.getResources().getString(R.string.not_participation_schedule_success));
					}else if(returnCode==IBMSProtocol.STATUS_CODE_EXIT_RECORD){
						Toast.makeText(CreateScheduleActivity.this, CreateScheduleActivity.this.getResources().getString(R.string.error_data_server), Toast.LENGTH_SHORT).show();
					}else if(returnCode==IBMSProtocol.STATUS_CODE_GENERIC_FAIL_CONECTTION){
						Toast.makeText(CreateScheduleActivity.this, CreateScheduleActivity.this.getResources().getString(R.string.error_network_connection), Toast.LENGTH_SHORT).show();
					} 
					else {
						showMessageToast(context.getResources().getString(R.string.not_participation_schedule_fail));
					}
					pg_load.setVisibility(View.GONE);
				}
			});
		}
		
		@Override
		public void finishgetAndroidNotifications(int countPage,final int resultCode,String resultMsg,
				final ArrayList<AndroidNotificationsModel> listAndroidNotificationsModels) {
			super.finishgetAndroidNotifications(countPage, resultCode, resultMsg,listAndroidNotificationsModels);
			runOnUiThread(new Runnable() {
				@Override
				public void run() {
					if(resultCode == IBMSProtocol.STATUS_CODE_OK){
						if(listAndroidNotificationsModels != null){
							for (int i = 0; i < listAndroidNotificationsModels.size(); i++) {
								final Dialog dialog = new Dialog(context);
								dialog.setContentView(R.layout.custom_dialog);
								EditText reason_repair = (EditText) dialog.findViewById(R.id.reason);
								Button send = (Button) dialog.findViewById(R.id.send);
								Button cancel = (Button) dialog.findViewById(R.id.cancel);
								send.setOnClickListener(new OnClickListener() {
									@Override
									public void onClick(View v) {
										//aaaaaa
									}
								});
								cancel.setOnClickListener(new OnClickListener() {
									@Override
									public void onClick(View v) {
										dialog.dismiss(); 
									}
								});
							}
						}
					}else if (resultCode == IBMSProtocol.STATUS_CODE_GENERIC_FAIL){
						Toast.makeText(context, context.getResources().getString(R.string.error_notification), Toast.LENGTH_SHORT).show();
					}else if (resultCode == IBMSProtocol.STATUS_CODE_GENERIC_FAIL_CONECTTION){
						Toast.makeText(context, context.getResources().getString(R.string.error_network_connection), Toast.LENGTH_SHORT).show();
					}
				}
			});
		}
		private void setCheck(int level) {
			switch (level) {
			case 1:
				ckbLow.setChecked(true);
				ckbMedium.setEnabled(false);
				ckbMedium.setTextColor(context.getResources().getColor(R.color.hint_color));
				ckbHigh.setEnabled(false);
				ckbHigh.setTextColor(context.getResources().getColor(R.color.hint_color));
				break;
			case 2:
				ckbLow.setEnabled(false);
				ckbLow.setTextColor(context.getResources().getColor(R.color.hint_color));
				ckbMedium.setChecked(true);
				ckbHigh.setEnabled(false);
				ckbHigh.setTextColor(context.getResources().getColor(R.color.hint_color));
				break;
			case 3:
				ckbLow.setEnabled(false);
				ckbLow.setTextColor(context.getResources().getColor(R.color.hint_color));
				ckbMedium.setEnabled(false);
				ckbMedium.setTextColor(context.getResources().getColor(R.color.hint_color));
				ckbHigh.setChecked(true);
				break;

			default:
				ckbLow.setChecked(true);
				ckbMedium.setEnabled(false);
				ckbMedium.setTextColor(context.getResources().getColor(R.color.hint_color));
				ckbHigh.setEnabled(false);
				ckbHigh.setTextColor(context.getResources().getColor(R.color.hint_color));
				break;
			}
		}
		
		@Override
		public void finishUpdateAndroidSchedule(final int returnCode, String resultMsg) {
			super.finishUpdateAndroidSchedule(returnCode, resultMsg);
			runOnUiThread(new Runnable() {
				@Override
				public void run() {
					if(returnCode == IBMSProtocol.STATUS_CODE_OK){
						showMessageToast(context.getResources().getString(R.string.change_schedule_sucess));
						ListSurgeryActivity.actionLaunch(context);
					}else if (returnCode == IBMSProtocol.STATUS_CODE_GENERIC_FAIL){
						Toast.makeText(context, context.getResources().getString(R.string.error_update_sergery), Toast.LENGTH_SHORT).show();
					}else if (returnCode == IBMSProtocol.STATUS_CODE_GENERIC_FAIL_CONECTTION){
						Toast.makeText(context, context.getResources().getString(R.string.error_network_connection), Toast.LENGTH_SHORT).show();
					} else {
						showMessageToast(context.getResources().getString(R.string.change_schedule_fail));
					}
					pg_load.setVisibility(View.GONE);
				}
			});
		}
	}
	
	private BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            //load lai thang List danh sach ki thuat vien
        	pg_load.setVisibility(View.VISIBLE);
            BMSCore.getInstance(context).taskGetDetailSergery(itemSergeryModel.getSurgeryId(), preferences.getUserAuthKey(context), mListener);
        }
    };
    private BroadcastReceiver receiver1 = new BroadcastReceiver() {
    	@Override
    	public void onReceive(Context context, Intent intent) {
    		//load lai thang List danh sach ki thuat vien
    		pg_load.setVisibility(View.VISIBLE);
    		BMSCore.getInstance(context).taskGetDetailSergery(itemSergeryModel.getSurgeryId(), preferences.getUserAuthKey(context), mListener);
    	}
    };
    private BroadcastReceiver receiver2 = new BroadcastReceiver() {
    	@Override
    	public void onReceive(Context context, Intent intent) {
    		//load lai thang List danh sach ki thuat vien
    		pg_load.setVisibility(View.VISIBLE);
    		BMSCore.getInstance(context).taskGetDetailSergery(itemSergeryModel.getSurgeryId(), preferences.getUserAuthKey(context), mListener);
    	}
    };
    
	protected void showMessageToast(final String message) {
		runOnUiThread(new Runnable() {
			@Override
			public void run() {
				Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
			}
		});
	}
	
	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		switch (buttonView.getId()) {
		case R.id.ckb_low:
			if(isChecked == true){
				ckbLow.setChecked(true);
				ckbMedium.setChecked(false);
				ckbHigh.setChecked(false);
				ckbLow.setTextColor(context.getResources().getColor(R.color.tv_color));
				ckbMedium.setTextColor(context.getResources().getColor(R.color.hint_color));
				ckbHigh.setTextColor(context.getResources().getColor(R.color.hint_color));
			} else {
				ckbLow.setChecked(false);
				ckbLow.setTextColor(context.getResources().getColor(R.color.tv_color));
				ckbMedium.setTextColor(context.getResources().getColor(R.color.tv_color));
				ckbHigh.setTextColor(context.getResources().getColor(R.color.tv_color));
			}
			
			break;
		case R.id.ckb_medium:
			if(isChecked == true){
				ckbLow.setChecked(false);
				ckbMedium.setChecked(true);
				ckbHigh.setChecked(false);
				ckbLow.setTextColor(context.getResources().getColor(R.color.hint_color));
				ckbMedium.setTextColor(context.getResources().getColor(R.color.tv_color));
				ckbHigh.setTextColor(context.getResources().getColor(R.color.hint_color));
			} else{
				ckbMedium.setChecked(false);
				ckbLow.setTextColor(context.getResources().getColor(R.color.tv_color));
				ckbMedium.setTextColor(context.getResources().getColor(R.color.tv_color));
				ckbHigh.setTextColor(context.getResources().getColor(R.color.tv_color));
			}
			
			break;
		case R.id.ckb_high:
			if(isChecked == true) {
				ckbLow.setChecked(false);
				ckbMedium.setChecked(false);
				ckbHigh.setChecked(true);
				ckbLow.setTextColor(context.getResources().getColor(R.color.hint_color));
				ckbMedium.setTextColor(context.getResources().getColor(R.color.hint_color));
				ckbHigh.setTextColor(context.getResources().getColor(R.color.tv_color));
			} else {
				ckbHigh.setChecked(false);
				ckbLow.setTextColor(context.getResources().getColor(R.color.tv_color));
				ckbMedium.setTextColor(context.getResources().getColor(R.color.tv_color));
				ckbHigh.setTextColor(context.getResources().getColor(R.color.tv_color));
			}
			
			break;

		default:
			break;
		}
		
	}

	private void showHideViewHead(Boolean check) {
		if(check){
			spCreator.setVisibility(View.VISIBLE);
			spDoctor.setVisibility(View.VISIBLE);
			spTypeSchedule.setVisibility(View.VISIBLE);
			etNameScheldule.setVisibility(View.VISIBLE);
			tvNameCreator.setVisibility(View.GONE);
			tvSurgery.setVisibility(View.GONE);
			tvNameDoctor1.setVisibility(View.GONE);
			tvTypeSchedule1.setVisibility(View.GONE);
		} else {
			tvSurgeryReady.setVisibility(View.VISIBLE);
			spCreator.setVisibility(View.GONE);
			spDoctor.setVisibility(View.GONE);
			spTypeSchedule.setVisibility(View.GONE);
			etNameScheldule.setVisibility(View.GONE);
			tvNameCreator.setVisibility(View.VISIBLE);
			tvSurgery.setVisibility(View.VISIBLE);
			tvNameDoctor1.setVisibility(View.VISIBLE);
			tvTypeSchedule1.setVisibility(View.VISIBLE);
		}
	}

	@SuppressLint("NewApi") private void showHideViewBackgroundEditText(Boolean check){
		if(check){
			spTimeHours.setEnabled(true);
			spTimeMinute.setEnabled(true);
			spDateTime.setEnabled(true);
			ckbHigh.setEnabled(true);
			ckbMedium.setEnabled(true);
			ckbLow.setEnabled(true);
			etRoom.setBackground(CreateScheduleActivity.this.getResources().getDrawable(R.drawable.bg_edt_room_selector));
			etRoom.setEnabled(true);
			etFalculty.setBackground(CreateScheduleActivity.this.getResources().getDrawable(R.drawable.bg_edt_falculty_selector));
			etFalculty.setEnabled(true);
			spHospital.setBackground(CreateScheduleActivity.this.getResources().getDrawable(R.drawable.bg_spinnerr_selector));
			spHospital.setEnabled(true);
			etExtrasInfo.setBackground(CreateScheduleActivity.this.getResources().getDrawable(R.drawable.area_text_selector));
			etExtrasInfo.setEnabled(true);
			etTechniquesRequirement.setBackground(CreateScheduleActivity.this.getResources().getDrawable(R.drawable.area_text_selector));
			etTechniquesRequirement.setEnabled(true);
			etPrice.setBackground(CreateScheduleActivity.this.getResources().getDrawable(R.drawable.bg_edt_selector));
			etPrice.setEnabled(true);
			spCurrentcy.setVisibility(View.VISIBLE);
		} else {
			spTimeHours.setEnabled(false);
			spTimeMinute.setEnabled(false);
			spDateTime.setEnabled(false);
			ckbHigh.setEnabled(false);
			ckbMedium.setEnabled(false);
			ckbLow.setEnabled(false);
			etRoom.setBackgroundResource(0);
			etRoom.setEnabled(false);
			etFalculty.setBackgroundResource(0);
			etFalculty.setEnabled(false);
			spHospital.setBackgroundResource(0);
			spHospital.setEnabled(false);
			etExtrasInfo.setBackgroundResource(0);
			etExtrasInfo.setEnabled(false);
			etTechniquesRequirement.setBackgroundResource(0);
			etTechniquesRequirement.setEnabled(false);
			etPrice.setBackgroundResource(0);
			String price = etPrice.getText().toString() +" "+ spCurrentcy.getText().toString();
			etPrice.setText(price);
			ckbHigh.setChecked(false);
			ckbMedium.setChecked(false);
			ckbLow.setChecked(false);
			etPrice.setEnabled(false);
			spCurrentcy.setVisibility(View.GONE);
		}
	}
	
	private void showHideViewBotton(Boolean check) {
		if(check){
			tvListTechnical.setVisibility(View.VISIBLE);
			lvListTechnical.setVisibility(View.VISIBLE);
			btAdditionalRequirement.setVisibility(View.VISIBLE);
			btKeySchelde.setVisibility(View.VISIBLE);
			btCancelSchelde.setVisibility(View.VISIBLE);
			Log.e("listComment3", listComment.size()+".");
			lvComment.setVisibility(View.VISIBLE);
			tvWriteRate.setVisibility(View.VISIBLE);
			etTittleRate.setVisibility(View.VISIBLE);
			etContentRate.setVisibility(View.VISIBLE);
			vComment.setVisibility(View.VISIBLE);
			btSendRate.setVisibility(View.VISIBLE);
			btApprove.setVisibility(View.VISIBLE);
			btCancelSchedule1.setVisibility(View.VISIBLE);
			iconDeleteChange.setVisibility(View.VISIBLE);
			etnameTechChange.setVisibility(View.VISIBLE);
		} else {
			tvListTechnical.setVisibility(View.GONE);
			lvListTechnical.setVisibility(View.GONE);
			btAdditionalRequirement.setVisibility(View.GONE);
			btKeySchelde.setVisibility(View.GONE);
			btCancelSchelde.setVisibility(View.GONE);
			tvComment.setVisibility(View.GONE);
			vDashComment.setVisibility(View.GONE);
			lvComment.setVisibility(View.GONE);
			tvWriteRate.setVisibility(View.GONE);
			etTittleRate.setVisibility(View.GONE);
			etContentRate.setVisibility(View.GONE);
			vComment.setVisibility(View.GONE);
			btSendRate.setVisibility(View.GONE);
			btApprove.setVisibility(View.GONE);
			btCancelSchedule1.setVisibility(View.GONE);
			iconDeleteChange.setVisibility(View.GONE);
			etnameTechChange.setVisibility(View.GONE);
		}
	}
	
	public static void hideKeybroad(Context ctx)
	{
	    InputMethodManager inputManager = (InputMethodManager) ctx.getSystemService(ctx.INPUT_METHOD_SERVICE);
	    inputManager.hideSoftInputFromWindow(new View(ctx).getWindowToken(), 0);
	}
}
